mkdir /data/wordpress
vim docker-compose.yml
version: '3.1'
services:
wordpress:
image: wordpress:php7.3-fpm
restart: always
ports:
- "9000:9000"
depends_on:
- db
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: FmGHHi#Jn1wQlHMc
WORDPRESS_DB_NAME: wordpress
volumes:
- ./data/wp_site:/var/www/html
db:
image: mysql:5.7
restart: always
ports:
- "8470:3306"
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: FmGHHi#Jn1wQlHMc
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- ./data/db_data:/var/lib/mysql
nginx:
image: nginx
restart: always
volumes:
- ./nginx/cert:/etc/nginx/cert
- ./nginx/conf.d:/etc/nginx/conf.d
- ./data/wp_site:/var/www/html
ports:
- "80:80"
- "443:443"
links:
- wordpress
mkdir -p nginx/{cert,conf.d}
vim nginx/conf.d/wordpress.conf
server {
listen 80;
server_name 127.0.0.1;
#ssl on;
root /var/www/html;
index index.php index.html;
#ssl_certificate cert/test.pem; #修改为自己的证书地址
#ssl_certificate_key cert/test.key; #修改为自己的密钥地址
#ssl_session_timeout 5m;
#ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
#ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#ssl_prefer_server_ciphers on;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass wordpress:9000; #wordpress地址
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
也可直接用官方的apache镜像;
version: '3.1'
services:
wordpress:
image: wordpress:latest
restart: always
ports:
- "80:80"
- "443:443"
depends_on:
- db
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: FmGHHi#Jn1wQlHMc
WORDPRESS_DB_NAME: wordpress
volumes:
- ./wp_site:/var/www/html
db:
image: mysql:5.7
restart: always
ports:
- "8470:3306"
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: FmGHHi#Jn1wQlHMc
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- ./db_data:/var/lib/mysql