What is Docker Compose?
Learn about Docker Compose and its advantages over plain Docker commands.
The simplest way to Dockerize an app is to:
Write a
Dockerfile
to compile and run the source code.Build a Docker image from the
Dockerfile
usingdocker build.
Run that image using
docker run
.
However, there are some downsides to this. For example, the actual commands used to build and run the container aren't saved or stored anywhere. So, if someone wants to check the configuration flags used to build and run the Docker images, they might not be able to do so. Or there might be cases when we need to run multiple containers on the same machine—like running multiple services in local dev setups or when an app depends on a database service.
Using plain Docker commands might prove to be very tedious for these cases. That's where Docker Compose comes to the rescue.
What is Docker Compose?
Docker Compose is a tool in Docker that's used to define the container configuration for apps so that they can run in a Docker container. Notice we said apps and not just an app. This is because with Compose, we can run multiple containers on the same host simultaneously, all with one single command.
Let's see how.
How does Compose work?
Compose uses a docker-compose.yml
file to store all the container configurations. As the name suggests, it's a YAML file with a very easy-to-read syntax. This file uses the Dockerfile
to figure out how to build the container images.
Get hands-on with 1200+ tech skills courses.