$linuxjunkies
>

docker-compose(1)

Define and run multi-container Docker applications using a YAML configuration file.

UbuntuDebianFedoraArch

Synopsis

docker-compose [OPTIONS] COMMAND [ARGS]...

Description

Docker Compose is a tool for defining and running multi-container Docker applications. You describe your application's services, networks, and volumes in a docker-compose.yml file, then use a single command to start, stop, and manage all containers.

Compose simplifies local development, testing, and CI/CD workflows by eliminating the need to run multiple docker commands. It's particularly useful for applications with dependencies like web servers, databases, and caches that need to communicate.

Common options

FlagWhat it does
-f, --file FILESpecify an alternate compose file (default: docker-compose.yml)
-p, --project-name NAMESet the project name (default: current directory name)
--profile PROFILESpecify a profile to enable (can be used multiple times)
-d, --detachRun containers in the background (for up command)
--no-depsDon't start linked services (for up and run commands)
--scale SERVICE=NUMRun NUM instances of a service (for up command)
-e, --env-file FILERead environment variables from a file
--remove-orphansRemove containers for services not defined in compose file
-v, --versionShow the version number
--no-colorDisable colored output

Examples

Start all services defined in docker-compose.yml in the foreground; creates networks, volumes, and containers as needed

docker-compose up

Start all services in the background (detached mode); useful for long-running applications

docker-compose up -d

Stop and remove all containers, networks, and volumes defined in the compose file

docker-compose down

List all running containers managed by this compose project with their status and ports

docker-compose ps

Follow (stream) logs from the 'web' service in real-time; omit service name to see all logs

docker-compose logs -f web

Execute a command in the running 'db' service container; useful for interactive database access

docker-compose exec db psql -U postgres

Rebuild all service images without using cached layers; useful when dependencies change

docker-compose build --no-cache

Restart the 'web' service and immediately tail its logs to verify it started correctly

docker-compose restart web && docker-compose logs web

Related commands