Nerd For Tech
Published in

Nerd For Tech

Docker Compose

We use docker based on commands like docker build, docker run,-v,-p, etc., every time we develop images or containers. Even though commands are long and repeated many times, we still type in command prompt/shell.

When it comes to technology, it’s all about convenience and reducing repetition. So docker comes with the solution called ‘Docker Compose.’ This comes as default when you download docker from the official site.

So Docker Compose helps us to manage multiple containers with ease. We need just one file ‘docker-compose. yaml’ file with inputs is given as key-value pairs. When we have this file, we have to give one command — docker-compose up or docker-compose down from the terminal that has the file — docker-compose .yaml.

Docker-compose is called management/orchestration (everything can be staged into a configuration file) of multiple containers.

How to write a yaml file?

yaml files depend on indentation for execution like python file.

Basic commands are

By default, docker-compose puts all services in a single network — They can be communicated with the service name, or we can also create a custom network in addition to the default network.

version: [what version of docker-compose you want to use] --> available official website  services:  [service_name]:-->frontend,backend,db etc.    
#a child will be two space indented

image:[official image name/custom image name/path to repository] or if no image exists

#we use '-' in front for lists in YAML
-[host directory]:[container directory] --> for bind mounts
-[named of volume]:[container directory] --> named volume --> needs to be included in meta volume at the end of file
-[container_path] --> for anonymous volume
#we use depends on key when we want to start some service before this service needs to be started

Originally published at on May 18, 2022.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Arjun Vaidy

Arjun Vaidy

Founder of a startup. I explain things through first principles and intuitive mental models