Here’s how to run a WordPress site and MySql server using docker-compose. This yaml file also includes a certbot container to create a certificate for your site. In addition, this will store configuration on the host vm for persistent storage.
version: "3.8"
services:
db:
image: mysql:5.7 # or use mysql:latest or any other version
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password123
MYSQL_DATABASE: databasename-db
MYSQL_USER: username
MYSQL_PASSWORD: password123
wordpress:
depends_on:
- db
image: wordpress:latest
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: username
WORDPRESS_DB_PASSWORD: password123
WORDPRESS_DB_NAME: username
volumes:
- wordpress:/var/www/html
nginx:
container_name: nginx
image: nginx:latest
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- ./nginx/conf:/etc/nginx/conf.d
- ./certbot/conf:/etc/nginx/ssl
- ./certbot/data:/var/www/html
certbot:
container_name: certbot
image: certbot/certbot:latest
command: certonly --webroot --webroot-path=/var/www/html --email myemail@gmail.com --agree-tos --no-eff-email -d askben.cloud -d www.askben.cloud
volumes:
- ./certbot/conf:/etc/letsencrypt
- ./certbot/logs:/var/log/letsencrypt
- ./certbot/data:/var/www/html
volumes:
db_data: {}
wordpress: {}
Reading time: 1 minute