Docker Compose


Docker Compose is a tool for defining and running multi-container Docker applications at the same time.

With Compose,
1. Use a YAML file to configure your application’s services.
2. Then, with a single command, you create and start all the services from your configuration.

Compose works in all environments:
2. Staging
3. Development
4. Testing as well as CI workflows.

Using Compose is basically a three-step process:
1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
2. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
3. Run docker compose up and the Docker compose command starts and runs your entire app. You can alternatively run docker-compose up using the docker-compose binary.

Simple Example

On this page you build a simple Python web application running on Docker Compose. The application uses the Flask framework and maintains a hit counter in Redis. While the sample uses Python, the concepts demonstrated here should be understandable even if you’re not familiar with it.


Install docker engine and docker compose

Step 1: Setup — Create directory with any name

Step 2: Create a Project file — Here I used

Step 3: Create text file -requirements.txt

Step 4: Create a Dockerfile

Step 5: Define services in a Compose (docker-compose.yml) file

Step 6: Build and run your app with Compose

Step 6: Finally check with browser — http://localhost:5000/

Note : Refresh the browser — you will see the count increment

Step 7: Edit the Compose file to add a bind mount

Step 8: Re-build and run the app with Compose

Step 8: Update the application

Note: Refresh the browser, It updates the changes

Step 8: Stop all services


Hope you all got some basic idea of Docker compose. If you need to know the basics of Docker you can visit Introduction to Docker.





Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Ansible dynamic inventory with AWS EC2

PSM1… and done

Dependency Inversion Principle explained

Why you should learn to program on the Raspberry Pi

How to run browser from Selenium without using System.setProperty

The Ultimate guideline to choose DevOps companies in the US

[44] Anonymous collaborations

LAND TO EMPIRE: Community roles structures

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Paul issack minoltan

Paul issack minoltan

More from Medium

Avoid SQL Injection in PostgreSQL and .Net Core REST API

Angular environment DevOps hack no one seems to talk about

Introduction to Docker and Container based development

[Solved] jvm 1 | Unrecognized option: — add-exports=java.base/jdk.internal.ref=ALL-UNNAMED