Docker Compose is a tool for defining and running multi-container Docker applications. When usind docker, running and managing multiple containers becomes cumbersome. Docker compose solves this problem.
You use yaml to configure your application services. The yaml file is always named docker-compose.yml
but you can give it a different name then specify it. Compose provides docker-compose
command to manage the containers defined in the yaml file.
Also check
- How to Install and Use Docker in Ubuntu 20.04
- How to install and configure docker In Centos 8
- Docker as a build agent – Run Jenkins builds on Docker
Installing docker-compose
You can run Compose on macOS, Windows, and 64-bit Linux
Docker Compose relies on Docker Engine, make sure you have Docker Engine installed before proceeding.
Install using pip
Use this command:
|
|
WordPress Mysql example
You can use Docker Compose to easily run WordPress in an isolated environment built with Docker containers. This quick-start guide demonstrates how to use Compose to set up and run WordPress.
Sample docker-compose.yaml
file:
|
|
|
|
Use http://localhost as the IP address, and open http://localhost:8000 in a web browser.
If you need to use sudo to bring up containers
|
|
Shutdown and cleanup
The command docker-compose down
removes the containers and default network, but preserves your WordPress database.
The command docker-compose down
volumes removes the containers, default network, and the WordPress database.