How to use the Docker-compose command line

Created
Modified

The following show the Docker-Compose version information:

Version information
docker-compose version
docker-compose -v
docker-compose --version
docker-compose version 1.25.0, build 0a186604
docker-py version: 4.1.0
CPython version: 3.7.4
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

Use -f to specify name and path of one or more Compose files:

Specify an alternate compose file
docker-compose -f ~/docker-compose.yml
multiple override files
docker-compose up -f override.yml override2.yml
Pulling db (postgres:latest)...
latest: Pulling from library/postgres
ef0380f84d05: Pull complete
50cf91dc1db8: Pull complete
......
cecf11b8ccf3: Pull complete
Digest: sha256:1364924c753d5ff7e2260cd34dc4ba05ebd40ee8193391220be0f9901d4e1651
Status: Downloaded newer image for postgres:latest

If you change a service’s Dockerfile or the contents of its build directory, run docker-compose build to rebuild it.

builds the images from the dockerfiles
docker-compose build
docker-compose build nginx
starts the services defined in the docker-compose.yml file
-d stands for detached
docker-compose up -d
Recreate containers
docker-compose up -d --force-recreate
docker_redis is up-to-date
docker_php is up-to-date
docker_nginx is up-to-date

Docker-compose Help Commands and Options

Define and run multi-container applications with Docker.

Usage:
  docker-compose [-f <arg>...] [--profile <name>...] [options] [COMMAND] [ARGS...]
  docker-compose -h|--help

Options:
-f, --file FILE
Specify an alternate compose file (default: docker-compose.yml)
-p, --project-name NAME
Specify an alternate project name (default: directory name)
--profile NAME
Specify a profile to enable
--verbose
Show more output
--log-level LEVEL
Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
--no-ansi
Do not print ANSI control characters
-v, --version
Print version and exit
-H, --host HOST
Daemon socket to connect to
--tls
Use TLS; implied by --tlsverify
--tlscacert CA_PATH
Trust certs signed only by this CA
--tlscert CLIENT_CERT_PATH
Path to TLS certificate file
--tlskey TLS_KEY_PATH
Path to TLS key file
--tlsverify
Use TLS and verify the remote
--skip-hostname-check
Don't check the daemon's hostname against the name specified in the client certificate
--project-directory PATH
Specify an alternate working directory (default: the path of the Compose file)
--compatibility
If set, Compose will attempt to convert deploy keys in v3 files to their non-Swarm equivalent
Commands:
build
Build or rebuild services
bundle
Generate a Docker bundle from the Compose file
config
Validate and view the Compose file
create
Create services
down
Stop and remove containers, networks, images, and volumes
events
Receive real time events from containers
exec
Execute a command in a running container
help
Get help on a command
images
List images
kill
Kill containers
logs
View output from containers
pause
Pause services
port
Print the public port for a port binding
ps
List containers
pull
Pull service images
push
Push service images
restart
Restart services
rm
Remove stopped containers
run
Run a one-off command
scale
Set number of containers for a service
start
Start services
stop
Stop services
top
Display the running processes
unpause
Unpause services
up
Create and start containers
version
Show the Docker-Compose version information

docker-compose config


Usage:
  docker-compose config [options]

Options:
--resolve-image-digests
Pin image tags to digests.
--no-interpolate
Don't interpolate environment variables.
-q, --quiet
Only validate the configuration, don't print anything.
--services
Print the service names, one per line.
--volumes
Print the volume names, one per line.
--hash="*"
Print the service config hash, one per line.
Set "service1,service2" for a list of specified services or use the wildcard symbol to display all services.

docker-compose down


Usage:
  docker-compose down [options]

Options:
--rmi type
Remove images. Type must be one of:'all': Remove all images used by any service.'local': Remove only images that don't have a custom tag set by the `image` field.
-v, --volumes
Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers.
--remove-orphans
Remove containers for services not defined in the Compose file
-t, --timeout TIMEOUT
Specify a shutdown timeout in seconds.(default: 10)

docker-compose events


Usage:
  docker-compose events [options]

Options:
--json
Output events as a stream of json objects
Output events as a stream of json objects
docker-compose events --json
{
    "time": "2020-11-20T18:01:03.615550",
    "type": "container",
    "action": "create",
    "id": "213cf7...5fc39a",
    "service": "web",
    "attributes": {
        "name": "application_web_1",
        "image": "alpine:edge"
    }
}

docker-compose images


Usage:
  docker-compose images [options] [SERVICE...]

Options:
-q, --quiet
Only display IDs
List images
docker-compose images
  Container Image Id       Size  
----------------------------------------
docker_mysql_1   1e4405fe1ea9   436.6 MB
docker_nginx_1   6d9f77a25acb   21.19 MB
docker_php_1     5ae217886afb   617.8 MB
docker_redis_1   a49ff3e0d85f   29.31 MB

docker-compose kill


Usage:
  docker-compose kill [options] [SERVICE...]

Options:
-s SIGNAL
SIGNAL to send to the container. Default signal is SIGKILL.

docker-compose logs


Usage:
  docker-compose logs [options] [SERVICE...]

Options:
--no-color
Produce monochrome output.
-f, --follow
Follow log output.
-t, --timestamps
Show timestamps.
--tail="all"
Number of lines to show from the end of the logs for each container.
--tail
docker-compose logs --tail=2 redis
Attaching to docker_redis_1
redis_1  | 1:M 22 Jun 2021 10:31:37.546 * DB loaded from disk: 0.009 seconds
redis_1  | 1:M 22 Jun 2021 10:31:37.546 * Ready to accept connections

docker-compose ps


Usage:
  docker-compose ps [options] [SERVICE...]

Options:
-q, --quiet
Only display IDs
--services
Display services
--filter KEY=VAL
Filter services by a property
-a, --all
Show all stopped containers (including those created by the run command)

docker-compose pull


Usage:
  docker-compose pull [options] [SERVICE...]

Options:
--ignore-pull-failures
Pull what it can and ignores images with pull failures.
--parallel
Deprecated, pull multiple images in parallel (enabled by default).
--no-parallel
Disable parallel pulling.
-q, --quiet
Pull without printing progress information
--include-deps
Also pull services declared as dependencies

Related Tags