docker-compose - Define and run multi-container applications
docker compose [-f FILE] [-p NAME] [--profile P] COMMAND
Options you will use
up [-d] [--build] [--wait] [SERVICE...]- Create networks and volumes, build/pull images, and start containers in depends_on order.
down [-v] [--rmi all|local]- Stop and remove containers and networks. Volumes only with -v.
ps [-a] / logs [-f] [--tail N] [SERVICE]- Status and logs, prefixed by service.
exec SERVICE CMD / run --rm SERVICE CMD- Run in an existing container / in a new one-off container.
config [--services|--volumes|--profiles]- The fully interpolated project. The fastest way to see what .env really produced.
build / pull / stop / start / restart- The usual lifecycle.
-f, --file FILE- Compose configuration files (repeatable; later files override earlier ones). Default compose.yaml.
-p, --project-name NAME- Project name (default: the directory name). Prefixes containers, networks and volumes.
--profile PROFILE- Enable a profile: services with profiles: [PROFILE] start only when it is on.
--env-file FILE- Specify an alternate environment file (default .env, used for ${VAR} interpolation).
--project-directory DIR- Specify an alternate working directory (default: the directory of the first compose file).
--ansi STRING- Control when to print ANSI control characters: never, always, auto.
--progress STRING- Set type of progress output: auto, tty, plain, json, quiet.
--dry-run- Execute command in dry run mode: show what would happen.
--parallel INT- Control max parallelism, -1 for unlimited.
Examples
$ docker compose up -dstart the project in the background
$ docker compose configsee the file after ${VAR} interpolation
$ docker compose --profile debug up -dinclude services in the debug profile
Gotchas
- .env in the project directory feeds ${VAR} interpolation in the compose file; env_file: feeds variables into the CONTAINER. They are different things.
- depends_on alone only orders startup. Use condition: service_healthy with a healthcheck to wait for readiness.
- Service names resolve by DNS on the project network (<project>_default).
Try docker-compose in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.