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 FILESpecify an alternate compose file (default: docker-compose.yml)-p, --project-name NAMESpecify an alternate project name (default: directory name)--profile NAMESpecify a profile to enable--verboseShow more output--log-level LEVELSet log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)--no-ansiDo not print ANSI control characters-v, --versionPrint version and exit-H, --host HOSTDaemon socket to connect to--tlsUse TLS; implied by --tlsverify--tlscacert CA_PATHTrust certs signed only by this CA--tlscert CLIENT_CERT_PATHPath to TLS certificate file--tlskey TLS_KEY_PATHPath to TLS key file--tlsverifyUse TLS and verify the remote--skip-hostname-checkDon't check the daemon's hostname against the name specified in the client certificate--project-directory PATHSpecify an alternate working directory (default: the path of the Compose file)--compatibilityIf set, Compose will attempt to convert deploy keys in v3 files to their non-Swarm equivalentCommands:buildBuild or rebuild servicesbundleGenerate a Docker bundle from the Compose fileconfigValidate and view the Compose filecreateCreate servicesdownStop and remove containers, networks, images, and volumeseventsReceive real time events from containersexecExecute a command in a running containerhelpGet help on a commandimagesList imageskillKill containerslogsView output from containerspausePause servicesportPrint the public port for a port bindingpsList containerspullPull service imagespushPush service imagesrestartRestart servicesrmRemove stopped containersrunRun a one-off commandscaleSet number of containers for a servicestartStart servicesstopStop servicestopDisplay the running processesunpauseUnpause servicesupCreate and start containersversionShow the Docker-Compose version information
docker-compose config
Usage:
docker-compose config [options]
Options:
--resolve-image-digestsPin image tags to digests.--no-interpolate Don't interpolate environment variables.-q, --quiet Only validate the configuration, don't print anything.--servicesPrint the service names, one per line.--volumesPrint 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 typeRemove 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, --volumesRemove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers.--remove-orphansRemove containers for services not defined in the Compose file-t, --timeout TIMEOUTSpecify a shutdown timeout in seconds.(default: 10)
docker-compose events
Usage:
docker-compose events [options]
Options:
--jsonOutput 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, --quietOnly 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 SIGNALSIGNAL to send to the container. Default signal is SIGKILL.
docker-compose logs
Usage:
docker-compose logs [options] [SERVICE...]
Options:
--no-colorProduce monochrome output.-f, --followFollow log output.-t, --timestampsShow 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, --quietOnly display IDs--servicesDisplay services--filter KEY=VALFilter services by a property-a, --allShow all stopped containers (including those created by the run command)
docker-compose pull
Usage:
docker-compose pull [options] [SERVICE...]
Options:
--ignore-pull-failuresPull what it can and ignores images with pull failures.--parallelDeprecated, pull multiple images in parallel (enabled by default).--no-parallelDisable parallel pulling.-q, --quietPull without printing progress information--include-depsAlso pull services declared as dependencies