0% found this document useful (0 votes)
392 views

Cheat Sheet Docker Compose

Docker Compose allows managing multiple Docker containers through a single docker-compose.yaml configuration file rather than separate docker commands. It defines services that map to containers, with options like build context, volumes, networks. The main commands are docker-compose up to start containers and docker-compose down to stop them. Using Compose simplifies defining and running multi-container apps versus individual run commands.

Uploaded by

Sri Vagirala
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
392 views

Cheat Sheet Docker Compose

Docker Compose allows managing multiple Docker containers through a single docker-compose.yaml configuration file rather than separate docker commands. It defines services that map to containers, with options like build context, volumes, networks. The main commands are docker-compose up to start containers and docker-compose down to stop them. Using Compose simplifies defining and running multi-container apps versus individual run commands.

Uploaded by

Sri Vagirala
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Docker Compose

Docker Compose is an additional tool, offered by the Docker ecosystem, which helps with
orchestration / management of multiple Containers. It can also be used for single Containers to
simplify building and launching.

Why?
Consider this example:

docker network create shop

docker build -t shop-node .

docker run -v logs:/app/logs --network shop --name shope-web shop-node

docker build -t shop-database

docker run -v data:/data/db --network shop --name shop-db shop-database

This is a very simple (made-up) example - yet you got quite a lot of commands to execute and
memorize to bring up all Containers required by this application.

And you have to run (most of) these commands whenever you change something in your code or
you need to bring up your Containers again for some other reason.

With Docker Compose, this gets much easier.

You can put your Container configuration into a docker-compose.yaml file and then use just one
command to bring up the entire environment: docker-compose up .

Docker Compose Files


A docker-compose.yaml file looks like this:

version: "3.8" # version of the Docker Compose spec which is being used

services: # "Services" are in the end the Containers that your app needs
web:
build: # Define the path to your Dockerfile for the image of this container
context: .
dockerfile: Dockerfile-web
volumes: # Define any required volumes / bind mounts
- logs:/app/logs
db:
build:
context: ./db
dockerfile: Dockerfile-web
volumes:
- data:/data/db

You can conveniently edit this file at any time and you just have a short, simple command which
you can use to bring up your Containers:

docker-compose up

You can find the full (possibly intimidating - you'll only need a small set of the available options
though) list of configurations here: https://docs.docker.com/compose/compose-file/

Important to keep in mind: When using Docker Compose, you automatically get a Network
for all your Containers - so you don't need to add your own Network unless you need multiple
Networks!

Docker Compose Key Commands


There are two key commands:

docker-compose up : Start all containers / services mentioned in the Docker Compose file

-d : Start in detached mode


--build : Force Docker Compose to re-evaluate / rebuild all images (otherwise, it only
does that if an image is missing)
docker-compose down : Stop and remove all containers / services

-v : Remove all Volumes used for the Containers - otherwise they stay around, even if
the Containers are removed

Of course, there are more commands. You'll see more commands in other course sections (e.g.
the "Utility Containers" and "Laravel Demo" sections) but you can of course also already dive
into the official command reference: https://docs.docker.com/compose/reference/

You might also like