Member-only story
Run Multiple Containers With Docker Compose
Execute multiple containers side by side without interfering with each other

What is Docker?
Docker has gained popularity for multiple reasons. One of them is creating portable containers which are fast and easy to deploy.
As mentioned on their website: “a container is something that packages your code along with any other dependencies so that it can be deployed across multiple platforms reliably”.
These containers can be run locally on your Windows, Mac, and Linux. Secondly, major cloud systems like AWS or Azure do support them out of the box. Lastly, it can be used on any hosting space where it can be installed and run. If you want to learn more Docker basics and need a cheat sheet for docker CLI, I wrote an introductory article about it here.
Here we will go deeper to understand some of the advanced features like running multiple containers.
Docker Compose
With docker-compose one can configure and start multiple containers with a single YAML file. This is really helpful if you are working on a technology stack with multiple technologies. As an example, if you are working on a project that requires MySQL database, python for AI/ML, Node.js for real-time processing & .NET for serving API. It would be cumbersome to set up such an environment for each team member. Docker alleviates this issue with the help of compose.
Understanding Docker Compose
docker compose
is a YAML file in which we can configure different types of services. Then with a single command, all containers were built and fired up. There are mainly 3 steps involved
- Generate a Dockerfile for each project.
- Setup services in
docker-compose.yml
file. - Fire up the containers.
We are now going to implement a solution for the above problem statement.
Prerequisites
One might expect to have all the technologies installed to run the above-discussed tech stack of MySQL, Python, NodeJS, .NET and PHP. Rather all you need is a docker engine running…