DevOps

5 Docker Compose Tips You Might Not Know

Docker Compose is more than just a tool to "start containers all at once." Recent updates have introduced numerous features that dramatically improve the developer experience. Here are 5 features that are surprisingly unknown but indispensable once you learn them.

1. Lightning Fast Dev with docker compose watch

Are you tired of the slowness of bind mounts or file permission issues? watch mode detects file changes on the host and automatically copies them into the container or triggers a rebuild.

services: web: build: . develop: watch: - action: sync path: ./web target: /app/web ignore: - node_modules/ - action: rebuild path: package.json

Run with docker compose watch, and source code changes are instantly synced, while package definition changes trigger an automatic rebuild. This is powerful even in environments where hot reload is tricky.

2. Managing Environments with profiles

"I don't want to run debug tools (like phpMyAdmin or pgAdmin) all the time, only when I need them." This is where profiles come in handy.

services: app: image: my-app db-admin: image: dpage/pgadmin4 profiles: - debug

A normal docker compose up won't start db-admin. It only starts when you specify docker compose up --profile debug. No more messy docker-compose.override.yml management.

3. The Right Way to Split Files: include

Did you use extends or shell scripts with multiple -f flags to split huge docker-compose.yml files? The include syntax is now officially supported.

# compose.yaml include: - path: ./infra/compose.yaml - path: ./backend/compose.yaml services: proxy: image: nginx depends_on: - backend

This allows you to easily integrate Compose files managed by different teams into a single project just by specifying the path.

4. healthcheck and condition: service_healthy

The classic "App starts and dies before DB is ready" problem. depends_on alone is not enough. Using service_healthy ensures the app waits until the "DB is up AND ready to accept connections".

services: db: image: postgres healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 10s timeout: 5s retries: 5 backend: build: . depends_on: db: condition: service_healthy

Free yourself from the restart loop hell.

5. The name Property

By default, Docker Compose uses the "folder name" as the project name (prefix for container names). This means if you rename the folder, it's treated as a different project, and volumes might get lost.

name: my-super-project services: ...

Defining name at the top level fixes the project name regardless of the folder name. This is especially important in CI/CD environments where directory names might change dynamically.

Conclusion

Docker Compose is evolving every day. Ditch the old habits (like writing version: '3') and embrace the new features.