Docker Compose 101
Configure and docker compose in 5 minutes for docker images
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services.
Whenever one has to run more than a container and have them to communicate with another,
Docker Compose comes to the rescue.
The core of docker compose can be understood with the below example.
Let’s say, we want to build an application with three services
myservice_1— its some JVM application that uses 2g of memory and needs to communicate with
redis(using tcp) and
- we want to share a storage volume across all three of the containers.
command: ["--cache", "cache:6379", "--backend_http", "http://backend_service:4000" ]
command: ["--http_port", "4000" ]
image — the name of the docker image.
command — the parameters / cli args to the docker image.
environment— the placeholder to provide env variables to the docker container.
volumes — provides mounting external storage to the docker container. Note, when the same external volume is mounted to more than a container then the file-system is shared across containers.
expose — a mechanism to allow sharing of ports to peer containers.
ports — to allow host machine to access container port
22 . One can reach this port using the host’s port
49100 . Note, its also possible to get access to range of ports as well.
Thank you for the quick read.
⛑ Suggestions / Feedback ! 😃