腾讯云主机部署Docker+WordPress+https+CDN(四) Docker部署wordpress

1. 安装docker

# 1. 安装基本软件
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum update -y && yum install -y docker-ce

# 配置国内源
cat <<EOF >/etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://mirror.ccs.tencentyun.com"
  ]
}
EOF

# 启动docker
systemctl daemon-reload && systemctl restart docker && systemctl enable docker

# 2. 安装docker-compose
yum update -y
yum install epel-release python3-pip -y
pip install --upgrade pip
pip install docker-compose

2. Docker安装WordPress

# 1. 准备docker-compose.yml
mkdir -p /root/docker

cat <<EOF >/root/docker/docker-compose.yml
version: '3.1'
services:
  nginx:
    image: nginx
    container_name: nginx
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /root/docker/nginx/conf/conf.d:/etc/nginx/conf.d:ro
      - /root/docker/nginx/conf/nginxconfig.io:/etc/nginx/nginxconfig.io:ro
      - /root/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro
      - /root/docker/nginx/html:/usr/share/nginx/html:rw
      - /root/docker/nginx/log:/var/log/nginx:rw
      - /root/docker/nginx/ssl:/etc/ssl:ro
    networks:
      - default

  wp:
    image: wordpress
    container_name: wordpress
    restart: always
    # ports:
    #   - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: ferrisyu
      WORDPRESS_DB_PASSWORD: Dwfe@4947
      WORDPRESS_DB_NAME: codingxx
    volumes:
      - /root/docker/wordpress:/var/www/html
    networks:
      - default

  db:
    image: mysql:5.7
    container_name: mysql
    restart: always
    environment:
      MYSQL_DATABASE: codingxx
      MYSQL_USER: ferrisyu
      MYSQL_PASSWORD: Dwfe@4947
      #因为后面要用root做数据库备份,这里就不使用随机密码了,自己设置一个复杂的
      #MYSQL_RANDOM_ROOT_PASSWORD: "1"
      MYSQL_ROOT_PASSWORD: Kdif@9854jef
    volumes:
      - /root/docker/db:/var/lib/mysql
    networks:
      - default

networks:
  default:
EOF

# 2. 准备nginx配置文件
mkdir -p /root/docker/nginx/conf
# 新建一个临时 nginx 容器
docker run --name nginx_temp -p 80:80 -d nginx
docker cp nginx_temp:/etc/nginx/conf.d /root/docker/nginx/conf/
docker cp nginx_temp:/etc/nginx/nginx.conf /root/docker/nginx/conf/

# 停止删除临时 nginx 容器
docker stop nginx_temp
docker rm nginx_temp

# 3. 启动容器
cd /root/docker
docker-compose up -d

3. nginx反向代理WordPress

# 1. 准备配置文件
cat <<EOF >/root/docker/nginx/conf/conf.d/codingsea.com.conf
server {
  listen 80;
  listen [::]:80;

  server_name codingsea.com;

  location / {
    proxy_pass http://wp;

        proxy_http_version    1.1;
        proxy_cache_bypass    \$http_upgrade;

        proxy_set_header Upgrade            \$http_upgrade;
        proxy_set_header Connection         "upgrade";
        proxy_set_header Host                \$host;
        proxy_set_header X-Real-IP            \$remote_addr;
        proxy_set_header X-Forwarded-For    \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto    \$scheme;
        proxy_set_header X-Forwarded-Host    \$host;
        proxy_set_header X-Forwarded-Port    \$server_port;
  }
}
  
EOF

# 2. 重启nginx
tmp=`docker ps | grep nginx | awk '{print $1}' | head -n 1`;docker restart $tmp

此时通过: http://xx.xx.xx.xx已经可以访问wordpress站点了。

建站  ·  开发  ·  读书  ·  教程
↑长按或扫码关注“编程之海”公众号↑
↑长按或扫码关注“编程之海”公众号↑
编程之海 版权所有丨如未注明,均为原创丨转载请注明转自:https://codingsea.com/wordpress-docker-wordpress-install/
0 0 投票数
文章评分
订阅评论
提醒
guest
0 评论
内联反馈
查看所有评论

0

0

930

0
希望看到您的想法,请您发表评论x