Docker版本需要20.10+,才能使用host.docker.internal访问宿主机;使用宿主机的MySQL
version: '3.1'
services:
wordpress:
image: wordpress:6.2.2
container_name: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: host.docker.internal:3306
WORDPRESS_DB_USER: someuser
WORDPRESS_DB_PASSWORD: somepasswd
WORDPRESS_DB_NAME: wordpress_db
volumes:
- /home/wordpress:/var/www/html
extra_hosts:
- "host.docker.internal:host-gateway"
Nginx反代配置
server {
listen 443 ssl;
server_name wp.example.com;
ssl_certificate ...;
ssl_certificate_key ...;
location /{
client_max_body_size 1536m;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Url $scheme://$host:$server_port;
proxy_pass http://127.0.0.1:8080;
}
}