Show Menu

Docker Compose Cheat Sheet by

Docker Compose


Docker­-Co­mpose: is a tool for defining and running multi-­con­tainer Docker applic­ations. With Compose, you use a YAML file to configure your applic­ation’s services. Then, with a single command, you create and start all the services from your config­ura­tion.
Need to good to yml file directory to succes­sfully run the docker­-co­mpose commands.
docker­-co­mpose start wordpr­ess_db :it will only start 1 service
but docker­-co­mpose start : will start all the services
similar is the case with other commands.

docker­-co­mpose start

Starts an existing service container.

docker­-co­mpose stop

-t, --timeout
specify a shutdown timeout in second­s.(­def­ault: 10)
Stops running containers without removing them. They can be started again with
docker­-co­mpose start

docker­-co­mpose pause

Pauses running containers of a service. They can be unpaused with docker­-co­mpose unpause

docker­-co­mpose unpause

Unpauses paused containers of a service.

docker­-co­mpose restart

Restarts all stopped and running services.

docker­-co­mpose ps

-q, --quiet
Only display IDs
Shows list of containers for a service.

docker­-co­mpose logs

-f, --follow
Follow log output.
Displays log output from services.

docker­-co­mpose top

View the processes running within each service container.


# creates a custom network called 
networks:   frontend:


# makes the
service available as the hostname

# (implies depend­s_on)
- db:dat­abase
- redis
# make sure
is alive before starting
- db


version: "3.7"
    container_name: "wordpress_db"
    image: "mysql:5.7"
      - ~/dockers/wordpress/.data/wordpress_db:/var/lib/mysql
      MYSQL_USER: gaurav
      MYSQL_PASSWORD: victory
      - wordpress_network
      - 3307:3306
    container_name: "wordpress_web"
    image: "wordpress"
      - ~/dockers/wordpress/.data/wordpress_web:/var/www/html
      WORDPRESS_DB_HOST: wordpress_db
      WORDPRESS_DB_USER: gaurav
      - wordpress_network
      - 8080:80
      - wordpress_db

docker­-co­mpose rm

Removes stopped service contai­ners.By default, anonymous volumes attached to containers are not removed. You can override this with -v. To list all volumes, use docker volume ls.
-f, --force – Don’t ask to confirm the removal
-s, --stop – Stop the contai­ners, if required, before removing
-v – Remove any anonymous volumes attached to containers

docker­-co­mpose pull

Pulls an image associated with a service defined in a docker­-co­mpo­se.yml file, but does not start containers based on those images.

docker compose up

docker­-co­mpose up
use docker­-co­mpo­se.yml
docker­-co­mpose -f <fi­len­ame.ym­l> -f <fi­len­ame­loc­al.y­ml> up
use custom yml files
-d, --detach
background detached mode
forcefully Build images before starting contai­ners.
skips the image build process
Recreate containers even if their config­uration and image haven’t changed.
Produce monochrome output.
--scale SERVIC­E=NUM
Scale SERVICE to NUM instances. Overrides the
setting in the Compose file if present.
docker­-co­mpose up is used to start a project. It tries to automate a series of operations including building a mirror, (re)cr­eating a service, starting a service, and associ­ating a servic­e-r­elated container.
It also builds the images if the images do not exist and starts the contai­ners:

docker­-co­mpose down

Stops containers and removes contai­ners, networks, volumes, and images
By default, the only things removed are:
- Containers for services defined in the Compose file
- Networks defined in the
section of the Compose file
- The default network, if one is used
created by
.Networks and volumes defined as
are never removed.

use -v to remove volumes also along with other things

docker­-co­mpose version

Prints the version of docker­-co­mpose.

docker­-co­mpose push

Pushes images for services to their respective regist­ry/­rep­ository

docker­-co­mpose run

Runs a one-time command against a service. For example, the following command starts the web service and runs bash as its command :
docker­-co­mpose run wordpr­ess_db bash

docker­-co­mpose config

Validate and view the Compose file.

docker­-co­mpose kill

Forces running containers to stop by sending a SIGKILL signal.

docker­-co­mpose bundle

A Dockerfile can be built into an image, and containers can be created from that image. Similarly, a docker­-co­mpo­se.yml can be built into a distri­buted applic­ation bundle

docker­-co­mpose build

only builds the images, does not start the contai­ners:


  # build from Dockerfile
  build: .
  # build from custom Dockerfile
    context: ./dir
  # build from image
  image: ubuntu
  image: ubuntu:14.04
  image: tutum/influxdb
  image: example-registry:4000/postgresql
  image: a4bc65fd


    - "3000"
    - "8000:80"  # guest:host
  # expose ports to linked services (not to host)
  expose: ["3000"]


 # command to execute
  command: bundle exec thin -p 3000
  command: [bundle, exec, thin, -p, 3000]
  # override the entrypoint
  entrypoint: /app/
  entrypoint: [php, -d, vendor/bin/phpunit]

Enviro­nment variables

  # environment vars
    RACK_ENV: development
    - RACK_ENV=development
  # environment vars from file
  env_file: .env
  env_file: [.env, .development.env]


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Ubuntu Compose Key Combinations Cheat Sheet
          Docker Cheat Sheet

          More Cheat Sheets by gauravpandey44