Docker Compose


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


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





I am a Professional Software Engineer

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