What is Docker Compose: Benefits and Basic Commands

Containers, and their first cousins–virtual machines–share several attributes. With the virtual machine (VM) as the first influence, containers have taken the concept and technology to the next step.

Docker is a widely-used container tool that developers and operation teams use to create and automate deploying applications in lightweight containers on VMs. This is done to ensure that applications work efficiently in multiple environments.

At the core, containers are a software package that works with all the dependencies required to run an application.

Let’s take a look at how the Docker containers are created.

Learn core Docker technologies such as Docker Hub, Docker Compose, Docker Swarn with the Docker Certified Associate Certification Training Course.

How Are Docker Containers Created?

A Docker image is built using a Docker file. The Docker file is a text-based script, and the text file within the Docker file has all the commands to run the appropriate technologies within the Docker image. 

The Docker image enables you to have a broad group of people run the same environment. If you want to share a Docker image, uploading it to Docker Hub can easily accomplish this. You can access and share on Docker Hub through the public Docker Hub website, or set up your private enterprise account. 

From Docker Hub, users can pull images and build containers that are consistent with the original Docker container that you created, to enable collaboration.

So, what if you want to use two containers in a single service? For example: 

Suppose you have more than one container in Docker. Let’s say a web server and a database are running in separate containers, which is typical for your data structure. The building, running, and connecting the containers from separate Docker files is difficult and can take a lot of time. This is where Docker Compose comes in. It facilitates multiple services running simultaneously.

DevOps Career Guide

A Guide to Becoming A DevOps EngineerDownload Now
DevOps Career Guide

What is Docker Compose?

To understand Docker Compose, let’s look at Myntra as an example. Myntra is a fashion e-commerce website similar to Amazon. You visit the Myntra website through your web browser and go through several activities, like logging in to your account, browsing a catalog, checking out, and so on. Behind each of these activities or services are different products, such as an account database, product database, cart database, and others that run behind the scenes.


Each of these can be considered a microservice. The more microservices you build into your environment, the more valuable it is to have each of these services in their containers. But as a developer, you should be able to jump from one container to another. This is where you can relate this example to Docker, where Docker Compose can connect different containers as a single service.

Docker Compose is used for running multiple containers as a single service. Each of the containers here run in isolation but can interact with each other when required. Docker Compose files are very easy to write in a scripting language called YAML, which is an XML-based language that stands for Yet Another Markup Language. Another great thing about Docker Compose is that users can activate all the services (containers) using a single command.

For example:

If you have an application that requires an NGINX server and Redis database, you can create a Docker Compose file that can run both the containers as a service without the need to start each one separately.


Benefits of Docker Compose

  • Single host deployment - This means you can run everything on a single piece of hardware
  • Quick and easy configuration - Due to YAML scripts
  • High productivity - Docker Compose reduces the time it takes to perform tasks
  • Security - All the containers are isolated from each other, reducing the threat landscape

Now, you might be thinking that Docker Compose is quite similar to Docker Swarm, but that’s not the case. Here are some of the differences between Docker Compose and Docker Swarm:


Basic Commands in Docker Compose

  • Start all services: Docker Compose up
  • Stop all services: Docker Compose down
  • Install Docker Compose using pip: pip install -U Docker-compose
  • Check the version of Docker Compose: Docker-compose-v
  • Run Docker Compose file: Docker-compose up -d
  • List the entire process: Docker ps
  • Scale a service - Docker Compose up -d -scale
  • Use YAML files to configure application services - Docker Compose.yml

These are some of the basic commands that you can use in Docker Compose. If you want to watch a demo on how you can use each of these commands in Docker Compose, click here to watch Simplilearn’s video tutorial for beginners. 

DevOps Certification Training Course

Gain expertise in the top DevOps toolsExplore Course
DevOps Certification Training Course

Learn More About Docker

If you want to master all things Docker, check out Simplilearn’s Docker In-Depth Certification Training Course today. In this comprehensive course, you will get access to four hours of self-paced learning, four end-of-chapter quizzes, and the opportunity to work on hands-on projects. 

About the Author


Simplilearn is one of the world’s leading providers of online training for Digital Marketing, Cloud Computing, Project Management, Data Science, IT, Software Development, and many other emerging technologies.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.