docker wordpress 部署/迁移要点

1 wordpress 容器部署

version: "3.8"
services:
  db:
    image: mysql:8.0
    command:
    - --default_authentication_plugin=mysql_native_password
    - --character-set-server=utf8mb4
    - --collation-server=utf8mb4_unicode_ci     
    volumes:
      - db_data:/var/lib/mysql
    ports:
      - "3308:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 111
      MYSQL_DATABASE: wordpress
      MYSQL_USER: user1
      MYSQL_PASSWORD: password
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3308
      WORDPRESS_DB_USER: user1
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_PASSWORD: password
    volumes:
      ["./html/:/var/www/html"]
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin
    restart: always
    ports:
      - '8001:80'
    environment:
      PMA_HOST: db
      PMA_PORT: 3308
      MYSQL_ROOT_PASSWORD: 111
volumes:
  db_data:

2. 原有的wordpress 目录下 wp-content/themes/ /wp-content/plugins/ 内容复制到新的 挂载点对应目录下

3 数据库恢复

方式1

mysql -uroot -p wordpress  < /root/wordpress.sql # mysql 命令 导入数据库

方式2

mysql>  source C:\Users\T440P\Desktop\test.sql   #进入mysql 命令用source命令

数据库其他命令

mysql 账户添加数据库权限
 
 grant all privileges on *.* to 'username'@'%' with grant option;

 flush privileges;

4 修改数据库原有域名

5 外层nginx 转发配置

docker里的 wordpress 拿到访问的域名,然后用php拼接到静态资源地址里, 所以外层 nginx 要把 用户的host 传给 wordpress,如下

proxy_set_header Host $host; # $host: 用户访问服务器header有’HOST’字段,就是host字段,如果没有,就是 server name里的值; $proxy_host 是 根据proxy_pass 的值走的
proxy_set_header X-Forwarded-Proto $scheme; #向转发的服务表明使用,访问的协议,如https

Leave a Reply

Your email address will not be published. Required fields are marked *