Docker Compose
It is a tool which is used to create and start Docker application by using a single command. We can use it to file to configure our application’s services.
It is a great tool for development, testing, and staging environments.
It provides the following commands for managing the whole lifecycle of our application.
- Start, stop and rebuild services
- View the status of running services
- Stream the log output of running services
- Run a one-off command on a service
To implement compose, it consists the following steps.
- Put Application environment variables inside the Dockerfile to access publicly.
- Provide services name in the docker-compose.yml file so they can be run together in an isolated environment.
- run docker-compose up and Compose will start and run your entire app.
A typical docker-compose.yml file has the following format and arguments.
// docker-compose.yml
Installing Docker Compose
Following are the instructions to install Docker Compose in Linux Ubuntu.
Docker-compose version
It says, permission denied. So, make file executable.
Now, check version again.
Running Application using Docker Compose
Example
Follow the following example
1) Create a Directory
2) Create a file app.py.
// app.py
3) Create a file requirements.txt.
// requirements.txt
4) Create a Dockerfile.
// Dockerfile
5) Create a Compose File.
// docker-compose.yml
6) Build and Run Docker App with Compose
After running the above command, it shows the following output.
Now, we can see the output by following the running http url.
Output:
Each time, when we refresh the page. It shows counter incremented by 1.