Docker Compose
Why?
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:
1.Production
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.
Prerequisites
Install docker engine and docker compose
Step 1: Setup — Create directory with any name
Step 2: Create a Project file — Here I used app.py
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
Conclusion
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.
Cheers..!