1. docker安装并开机自启

1
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh && docker --version && systemctl start docker && systemctl enable docker && systemctl restart docker

2. docker-compose安装

1
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose && docker-compose --version

3. 新建ghost根目录

1
mkdir ~/ghost-blog && cd ~/ghost-blog && touch docker-compose.yml

4. docker-compose配置文件

编辑docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
version: '3.1'
services:
ghost:
image: ghost:latest
container_name: ghost
restart: always
volumes:
- ./data:/var/lib/ghost/content
ports:
- 8080:2368
environment:
database__client: mysql
database__connection__host: 172.17.0.1
database__connection__user: ghost
database__connection__password: ghost
database__connection__database: ghost
#database__connection__port: 3306
url: http://your-domain

networks:
extnetwork:
ipv4_address: 172.19.0.2

#新建network配置,目的是为了固定ip地址,mysql权限可以设置为只允许容器ip 172.19.0.2 访问
networks:
extnetwork:
ipam:
config:
- subnet: 172.19.0.0/16
gateway: 172.19.0.1

5. 配置mysql

新建一个mysql数据库,配置和上面docker-compose.yml文件对应起来,并设置只允许172.19.0.2访问。


6. docker-compose启动ghost博客

1
cd ~/gost-blog && touch docker-compose.yml

若是可以在 http://your-ip:8080 访问到你的ghost说明配置成功,若失败,则可以通过docker logs -f ghost查看ghost日志排错。


7. 配置反向代理

推荐使用nginx进行配置,在nginx配置文件中加入反代配置:

1
2
3
4
5
6
7
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8080;
}

之后就可以在 http://your-domain 访问到你的网站了!


8. 网站配置

网站后台路径: http://your-domain/ghost