Let’s talk about Docker Compose
Docker Compose is a tool that helps us to handle multiple containers as a single unit.
To use Docker Compose we need a configuration file docker-compose.yml
.
docker-compose.yml
version: '3'
services:
web: // service web
build:
context: .
dockerfile: Dockerfile
ports:
- 8080:80
depends_on:
- db
db: // service db
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: my_database
MYSQL_USER: my_user
MYSQL_PASSWORD: my_password
Then we can use docker-compose up
to build the images and run the containers.
Other Docker Compose commands
docker-compose down
: stop & remove the containers.docker-compose ps
: list running containers.docker-compose exec <service-name> <command>
: execute a command in a running container.