Docker Compose

Sikandar Zaman Virk
5 min readSep 16, 2022

--

This tutorial is written for the people which have some basic knowledge of docker and facing some issues or want to make their working more efficient. So if you know basics of docker and want to know about Docker Compose, this will be very helpful for you. And even if you do not know much about docker, this will be perfectly understandable for you.

In this writing, we will not go into complexities of Docker Compose And how it runs, instead, we will learns why even we need Docker Compose? What are the issues that we are facing? What is Docker Compose and how it solve these problems? What is yml file in Docker Compose ?

So these are the topics that we will cover in this tutorial.

1-What is docker compose?

2-Why we need docker compose or problems that we are facing?

3-What are the benefits of docker compose?

4-Basic understanding of .YML file.

1-What is docker compose?

Docker compose is a tool that was developed to help define and run multi-container applications. With Compose, we can create a YAML file to define all the services of our application and with a single command, we can create and start our services.

2-Why we need docker compose or problems that we are facing?

So the first question that comes to mind that why should we use Docker Compose? What are problems that we are facing ?

Handle more than one containers:

So we know most of the applications are multitasking. They have front end, back end and database etc. So we have to make separate containers for each task. And we also have to write separate commands to build and run those containers. This requires a lot of time. As a user, we do not want to write all these commands.

Communication Problem b/w containers:

Other major problem is communication (networking) between different containers. Suppose we three different containers and we want communication between them. We have to write at least 2³ commands to enable networking (communication) between them.

networking

Separately up and down all containers:

Usually, we up and down containers one by one. If we have multiple containers, every time we will up all the containers one by one for use and after that we have to down all of them one by one. This is also an irritating task.

Time consuming:

And by handling each container separately, it we require more time. And as a developer, it is not ideal for us to waste time. So this is also a big issue.

So now, I hope we all understand the problems.

Here is time when docker compose comes in place. Docker compose make it very easy to handle these problems.

3-What are the benefits of docker compose?

Docker compose is best solution of these problems. By using docker compose we do not need to write build and run run commands for each container.

Networking:

You can see below network in the bottom of diagram in compose.yml file. This is for the networking between all services. This enables the communication between all services. We do not have to write all commands manually.If we do not mention this keyword in our yml file, then this will be added by default. So if you do not mention it, this will also work fine.

UP and Down all containers with single command:

We can up all services with a single command in YAML file. And in the same way we can down all services with just one command.

Time efficient:

This saves our time and makes our work more efficient.

4-Basic understanding of .YML file.

In docker compose, we write a YAML file and in that file we configure all service that our application require.

compose.yml

To explain this to you in a simple way, i will explain you the above diagram. For example we have three services user interface (UI), data base (DB) and any third service i.e test. Now, we will configure all these three services in a single yml file. We write services in the start and below that we just mention the names of all services. And below every service we mention image name, ports no. and we could mention the path also.

To get the clear idea you can see the figure below. A docker Compose file looks something like this.

DockerCompose.yml

You can see version in the start of file. Its optional, you can skip this also.

So this is all about Docker Compose. We will see more details in the next part. So stay tuned for the next part :)

How to install Docker Compose:

You can visit the website mentioned below to see how to install compose.

You can install Docker Compose on different platforms from this website. It gives you the option to install on any platform like

1-Linux

2-Mac

3-Windows

You can see all the necessary information about installation from here.

References:

--

--