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:
Install Docker Compose plugin (recommended)
sudo apt update
sudo apt install docker-compose-plugin
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.