Docker Compose
Overview¶
Docker Compose is a tool for defining and running multi-container applications. It simplifies the control of our entire application stack, making it easy to manage services, networks, and volumes in a single, comprehensible YAML configuration file.
Compose File¶
Docker Compose relies on a YAML configuration file, usually named:
compose.yaml
(preferred)compose.yml
docker-compose.yaml
docker-compose.yaml
Compose Specification¶
compose.yaml (example)
version: 3.8 # (1)!
name: myapp # (2)!
services: # (3)!
fe:
container_name: fe # (4)!
build: . # (5)!
be:
container_name: be
image: imagename:tag # (6)!
networks: # (7)!
my-network:
volumes: # (8)!
my-volume:
configs: # (9)!
http_config:
external: true
secrets: # (10)!
server-certificate:
file: ./server.cert
- version: defined by the Compose Specification for backward compatibility. It is only informative & optional.
- name: name of project, as prefix for every services.
- services: define services. In the example, there 2 services, "fe" and "be".
- container_name: container name of service
- build: path of dockerfile for build image
- image: If not use buid (path of dockerfile), we can also provide base image, image is define base image that used for the service
- networks: define custom network
- volumes: define custom volume
- configs: define config needed
- secrets: define secrets needed