安装Docker Compose并迁移WordPress至Docker 

发布于 2022-11-28  154 次阅读


前几天惨遭脱库,55555

“To recover your lost Database send 0.018 Bitcoin (BTC) to our Bitcoin address: 手动打码 After this, contact us by email with your Server IP or Domain Name and a Proof of Payment (Payment ID). Your Database is downloaded and backed up on our servers. Backups that we have right now: 手动打码. Any email without your server IP Address or Domain Name and a Proof of Payment together will be ignored. If we dont receive your payment in the next 5 Days, we will delete or leak your sensitive information.”

无奈翻出陈年冷备份恢复一下,55555

安装Docker

apt update
apt upgrade
apt-get update
apt-get upgrade

apt-get install curl

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

安装Docker Compose

curl -L "https://github.com/docker/compose/releases/download/v2.13.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose 

chmod +x /usr/local/bin/docker-compose
 
docker-compose --version

Docker拉取Wordpress及MySQL

mkdir -p /data/wordpress

nano /data/wordpress/stack.yml
version: '3'
services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 密码1
      MYSQL_DATABASE: wp
      MYSQL_USER: wp
      MYSQL_PASSWORD: 密码2
    ports:
      - "3306:3306"
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      - wp_site:/var/www/html
    ports:
      - "801:80"
      - "4431:443"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wp
      WORDPRESS_DB_PASSWORD: 密码2
      WORDPRESS_DB_NAME: wp
volumes:
  db_data:
  wp_site:
docker-compose -f /data/wordpress/stack.yml up -d

上传并配置原wp数据库备份

将原wordpress数据库备份文件上传至/data/wordpress,并拷贝至docker wp数据库/opt

cd /data/wordpress
 
docker cp wp.sql wordpress-db-1:/opt/

进入docker wordpress的mysql,并替换wp数据库,建议直接用navicat编辑数据库!

以下是用code的方式(不推荐)

docker exec -it wordpress-db-1 bash
 
#如果不设置max_allowed_packet,该版本默认4M,可能导致无法替换wp数据库,因此先修改默认上限
 
mysql -uroot -p【密码1】
 
set global max_allowed_packet = 100 * 1024 * 1024;
 
#命令行修改之后,需要退出当前回话(关闭当前mysql server链接),然后重新登录才能查看修改后的值。通过命令行修改只能临时生效,下次数据库重启后又复原了。max_allowed_packet 最大值是1G(1073741824)
 
exit
 
mysql -uroot -p【密码1】
 
select @@max_allowed_packet;
 
exit
 
#替换wp数据库
 
mysql -uroot -p wp>/opt/wp.sql
 
exit

将原wordpress wp-content备份文件夹上传至/data/wordpress/wordpress,拷贝至docker wordpress,并修改wordpress权限

cd /data/wordpress
docker cp wordpress/wp-content/plugins wordpress-wordpress-1:/opt/
docker cp wordpress/wp-content/themes wordpress-wordpress-1:/opt/
docker cp wordpress/wp-content/uploads wordpress-wordpress-1:/opt/
docker exec -it wordpress-wordpress-1 bash
cp -r /opt/* /var/www/html/wp-content/
chown -R www-data:www-data /var/www/html
exit

访问ip:801即可


Love is merely a madness.