Docker compose is a tool for defining and running multi-container docker applications. Docker compose can configure your application services inside a yaml file called the docker-compose.yml You can start all services with a single command and stop all your application services with a single command too. A Docker container is a way to package applications with all the necessary dependencies and configurations. The container package is portable and easily shared between your development and engineering teams.

Docker compose lets you manage multiple containers and run all your multi-container applications. With the yaml file, you can configure application services, build your containers, and start your containers.


In this tutorial, we’ll learn how to configure and run containers using Docker Compose.

Build and Run Applications with Docker Compose

In a docker-compose file, you can map your whole commands with their configuration into a file for your container workflow. In a docker-compose.yml file, we have the version of your docker-compose and your services list.

After specifying your services name, you need to write the image where the app will be built, with your ports and environment variables. In this tutorial, we’ll use MongoDB and MongoExpress images to build our containers.

version: '3'
   image: mongo
     - 27017:27017
   # path of mongodb container
     - mongo-data:/data/db

  • Next, in your mongo-express configuration, you must configure your yaml file and enter the image name, port number, and environment variables. Docker compose will take care of creating a common network for your containers.
   image: mongo-express
     - 8080:8081

  • Next, go to your command line and start your containers using the docker-compose file. Run the docker-compose -f <file.yaml> up command, this will start all the containers in your yaml file.

  • You can see that the command is pulling and downloading your mongo image with the latest tag.
  • We started both containers simultaneously; you can see the logs of both containers in your CLI. The MongoDB container has to start immediately so that the Mongo Express container can establish a connection with your MongoDB database container.
  • Wait for some minutes; you can see your request is now successful.
  • Back in your terminal, you can see your Docker containers with the ports.
  • Next, access your mongo-express server running on port 8080
  • Create your database, and give it a name.
  • You can see your database Stats and Collections.
  • When you create a new collection, it creates the Tools, Collection Stats, and Indexes for your Mongo Express workflow App.
  • When you’re done with the configuration, you can tear down your containers using the docker-compose -f docker-compose.yaml down command.


Docker-compose is a tool to help define and share multi-container applications. It’s an important tool for any application that needs multiple microservices, as it allows each service to easily be in a separately managed container. With the docker-compose file, you can run multiple services and build multi-service container workflows effectively.