-
服务器准备:
-
以root账号登录,如果不是root,后面指令需要加sudo
apt update
apt install apt-transport-https ca-certificates curl gnupg lsb-release
- 添加GPG密钥,推荐国内源
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# 官方源
# curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- 添加仓库
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/debian \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
# 官方源
# echo \
# "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
# $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
- 安装Docker
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
- 检查Docker安装
docker version
systemctl status docker
7. Docker国内镜像配置
nano /etc/docker/daemon.json
输入以下内容,Ctrl+X Y 保存
{
"registry-mirrors": [
"https://mirror.ccs.tencentyun.com"
]
}
(因为我是腾讯云服务器,所以用的腾讯镜像,也可以选下面这些)
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"https://docker.mirrors.ustc.edu.cn",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com"
]
}
重启docker
systemctl restart docker
- 新建一个文件夹
wordpress
并cd进去
mkdir wordpress && cd wordpress
- 新建一个
docker-compose.yaml
并编辑
nano docker-compose.yaml
复制进入以下内容:
services:
wordpress:
depends_on:
db:
condition: service_healthy
image: wordpress:php8.3
ports:
- "24729:80" # 外部端口 24729可以改成别的
volumes:
- ./wordpress:/var/www/html
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
db:
image: mysql:5.7
volumes:
- ./db_data:/var/lib/mysql
# 设置环境变量, environment 的值可以覆盖 env_file 的值
environment:
MYSQL_ROOT_PASSWORD: mywordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
healthcheck:
test: mysql --user=root --password='mywordpress' -e "SELECT 1;"
interval: 10s
timeout: 5s
retries: 10
- 启动
docker compose up -d
-
打开浏览器,输入
http://IP:24729
(端口号和docker compose里写的一样)
按需要填写站点信息:
进入后台,就可以配置主题、编写文章了 -
(可选操作)设置Nginx代理,把某个域名转发到docker
cd /etc/nginx
新建一个配置文件.conf
server {
listen 80;
listen [::]:80;
server_name XXX.XXXX.com;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name XXX.XXXX.com;
ssl_certificate /etc/nginx/cert/XXX.XXXX.com_nginx/XXX.XXXX.com_bundle.crt;
ssl_certificate_key /etc/nginx/cert/XXX.XXXX.com_nginx/XXX.XXXX.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://localhost:24729;
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;
}
}
如果不用HTTPS 可以用这个配置
server{
listen 80;
listen [::]:80;
server_name XXX.XXXX.com;
location / {
proxy_pass http://localhost:24729;
proxy_redirect default;
}
}