You are here
Home > Software Development > Containerize WordPress Using Docker

Containerize WordPress Using Docker

For Single Site without Proxy:

docker-compose.yml

version: ‘3.3’

services:

web:
image: wordpress
restart: always
depends_on:
– mysql
links:
– mysql
expose:
– 80
ports:
– 80:80
environment:
– WORDPRESS_DB_NAME=db_name
– WORDPRESS_TABLE_PREFIX=wp_
– WORDPRESS_DB_HOST=mysql
– WORDPRESS_DB_PASSWORD=db_wordpress_user_password
– WORDPRESS_DB_USER=db_wordpress_user
– VIRTUAL_HOST=x.example.com
volumes:
– ./html:/var/www/html
networks:
– wordpress-network

mysql:
image: mysql
command: –default-authentication-plugin=mysql_native_password
container_name: mysql
restart: always
volumes:
– ./mysql:/var/lib/mysql
environment:
– MYSQL_ROOT_PASSWORD=mysql_root_password
– MYSQL_USER=db_wordpress_user
– MYSQL_PASSWORD=db_wordpress_user_password
– MYSQL_DATABASE=db_name
– MYSQL_ROOT_HOST=%
networks:
– wordpress-network

networks:
wordpress-network:

 

For Single Site with Proxy:

docker-compose.yml

version: ‘3.3’

services:

web:
image: wordpress
restart: always
depends_on:
– mysql
links:
– mysql
expose:
– 80
environment:
– WORDPRESS_DB_NAME=db_name
– WORDPRESS_TABLE_PREFIX=wp_
– WORDPRESS_DB_HOST=mysql
– WORDPRESS_DB_PASSWORD=db_wordpress_user_password
– WORDPRESS_DB_USER=db_wordpress_user
– VIRTUAL_HOST=x.example.com
– LETSENCRYPT_EMAIL=x@example.com
– LETSENCRYPT_HOST=x.example.com
volumes:
– ./html:/var/www/html
networks:
– wordpress-network

mysql:
image: mysql
command: –default-authentication-plugin=mysql_native_password
container_name: mysql
restart: always
volumes:
– ./mysql:/var/lib/mysql
environment:
– MYSQL_ROOT_PASSWORD=mysql_root_password
– MYSQL_USER=db_wordpress_user
– MYSQL_PASSWORD=db_wordpress_user_password
– MYSQL_DATABASE=db_name
– MYSQL_ROOT_HOST=%
networks:
– wordpress-network

nginx-proxy:
image: jwilder/nginx-proxy
links:
– web
ports:
– 80:80
– 443:443
volumes:
– /var/run/docker.sock:/tmp/docker.sock:ro
– ./certs:/etc/nginx/certs:ro
– ./vhost:/etc/nginx/vhost.d
– ./nginx:/usr/share/nginx/html
labels:
– com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy
networks:
– wordpress-network

nginx-letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
volumes:
– /var/run/docker.sock:/var/run/docker.sock:ro
– ./certs:/etc/nginx/certs:rw
– ./vhost:/etc/nginx/vhost.d
– ./nginx:/usr/share/nginx/html
depends_on:
– nginx-proxy
networks:
– wordpress-network

networks:
wordpress-network:

 

For Multiple Sites with Proxy:

Create directories for sites

mkdir site-a

mkdir site-b

mkdir site-c

mkdir mysql

mkdir proxy

docker-compose.yml for site-a
version: ‘3.3’

services:
site-a:
image: wordpress
restart: always
environment:
– WORDPRESS_DB_NAME=db_name
– WORDPRESS_TABLE_PREFIX=wp_
– WORDPRESS_DB_HOST=mysql
– WORDPRESS_DB_PASSWORD=db_wordpress_user_password
– WORDPRESS_DB_USER=db_wordpress_user
– VIRTUAL_HOST=x.example.com
– LETSENCRYPT_EMAIL=x@example.com
– LETSENCRYPT_HOST=x.example.com
volumes:
– ./html:/var/www/html
networks:
– site-a-network
– proxy_proxy-network
– mysql_mysql-global-network

networks:
site-a-network:
proxy_proxy-network:
external: true
mysql_mysql-global-network:
external: true

docker-compose.yml for mysql
version: ‘3.3’

services:
mysql-global:
image: mysql
command: –default-authentication-plugin=mysql_native_password
container_name: mysql-global
restart: always
volumes:
– ./mysql:/var/lib/mysql
environment:
– MYSQL_ROOT_PASSWORD=mysql_root_password
– MYSQL_USER=db_wordpress_user
– MYSQL_PASSWORD=db_wordpress_user_password
– MYSQL_DATABASE=db_name
– MYSQL_ROOT_HOST=%
networks:
– mysql-global-network
networks:
mysql-global-network:

docker-compose.yml for proxy
version: ‘3.3’

services:
nginx-proxy:
image: jwilder/nginx-proxy
ports:
– 80:80
– 443:443
volumes:
– /var/run/docker.sock:/tmp/docker.sock:ro
– ./certs:/etc/nginx/certs:ro
– ./vhost:/etc/nginx/vhost.d
– ./nginx:/usr/share/nginx/html
labels:
– com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy
networks:
– proxy-network

nginx-letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
volumes:
– /var/run/docker.sock:/var/run/docker.sock:ro
– ./certs:/etc/nginx/certs:rw
– ./vhost:/etc/nginx/vhost.d
– ./nginx:/usr/share/nginx/html
depends_on:
– nginx-proxy
networks:
– proxy-network

networks:
proxy-network:

Leave a Reply

Top