Docker Compose – Decomposed
(MySQL-WordPress Example)
Compose file syntax version
(latest 3.7) version: ‘3.7’
Configuration object for
containers services:
Name of the Service db:
Base Docker image for
container created by db service image: mysql:5.7
Volume name: Mount Path volumes:
within the container
- db_data:/var/lib/mysql
restart policy set to “always” restart: always
environment:
Passing log-in info through
environment variables in
- MYSQL_ROOT_PASSWORD: abc
<key>: <value> form - MYSQL_DATABASE: wordpress
- MYSQL_USER: wordpress
- MYSQL_PASSWORD: wordpress
xfor
Name of the Second Service wordpress:
Explains service dependencies. depends_on:
wordpress service will start after db service. - db
image: wordpress:latest
Port mapping as strings between ports:
“<host_PORT>:<container_PORT>” - "8000:80“
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
Create a reusable named volume for
both services. volumes:
db_data:
More Compose Parameters