Junior
What is Docker Compose?
sobes.tech AI
Answer from AI
Docker Compose is a tool for defining and running multi-container Docker applications. It allows managing multiple related services in a single configuration file.
Key features:
- Works on all platforms supporting Docker.
- Uses a YAML file format (
docker-compose.yml) to describe services, networks, and volumes. - Enables defining dependencies between services.
- Ensures reproducibility of environments for development, testing, and production.
Main commands:
| Command | Description |
|---|---|
up |
Creates and starts services. |
down |
Stops and removes containers, networks, volumes, and images (by default). |
build |
Builds images for services. |
start |
Starts stopped services. |
stop |
Stops running services. |
restart |
Restarts services. |
ps |
Displays container status. |
logs |
Shows service logs. |
exec |
Executes a command in a running container. |
Simple example of a docker-compose.yml file:
version: '3.8' # Compose syntax version
services:
web: # Service name
image: nginx:latest # Used image
ports:
- "80:80" # Port forwarding (host:container)
volumes:
- ./html:/usr/share/nginx/html # Volume mounting (host:container)
app: # Another service
build: . # Builds image from Dockerfile in current directory
ports:
- "5000:5000"
depends_on: # Dependency: app starts after web
- web