Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
To install Docker Compose, follow these steps:
Download Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep -Po '"tag_name": "\K.*\d')" -o /usr/local/bin/docker-compose
Apply executable permissions
sudo chmod +x /usr/local/bin/docker-compose
Verify installation
docker-compose --version
Create a docker-compose.yml
file in your project directory:
version: '3'
services:
web:
image: nginx
ports:
- "80:80"
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: example
Start your application with:
docker-compose up
Stop your application with:
docker-compose down
docker-compose up
: Create and start containers.docker-compose down
: Stop and remove containers, networks, images, and volumes.docker-compose ps
: List containers.docker-compose logs
: View output from containers.docker-compose exec
: Execute a command in a running container.Docker Compose simplifies the process of managing multi-container applications, making it an essential tool for Linux server administrators.