Deploy Ghost with Docker and Traefik 2

我很怀念从前需要斟酌字句好好写文章的blog年代。那个时候我用Google Reader订阅一些我感兴趣的博客,用QQ和MSN Messager跟朋友即时联系,有什么感悟就写在MSN Live Space上跟朋友们交流想法。即使年轻的时候感情丰富,经常文思泉涌,但是一篇文章写起来还是非常费时。社交媒体的到来把所有的想法都变成了快餐,也造成了大一部分人根本没有看整篇文章的习惯,贴标签,立人设,带节奏,常反转的网络风气也由此而来。毕竟仔细研读一个人的文章,了解其TA的想法实在费时费力,还是贴标签简单。

像我这样的老古董即使文笔特差,也还是坚持更新blog。现在写blog已经没有了当初与人交流想法的初衷,只是为了记录自己生活的点点滴滴。

现在的blog或者说搭建网站的平台多如牛毛,无论是常规的WordPress还是各有特点的Static Site Generator (Hexo, Hugo, Jekyll) 都是非常好的选择。今天要教大家搭建的是Ghost我在之前的文章已经谈过,今天只是更新一下如何在Traefik 2的环境下搭建这个平台。

我们的文件夹结构如下:

1
2
3
4
5
├── ghost-blog/
│ ├── docker-compose.yml
│ └── ghost/
│ ├── config.production.json
│ └── content/

视频已经更新,请点击阅读全文查看视频。

我们先创建文件。

1
2
3
mkdir -p ghost-blog/ghost/content
touch ghost-blog/docker-compose.yml
touch ghost-blog/ghost/config.production.json

然后把docker-compose.yml文件发出来。

请注意,我的docker-compose.yml文件需要搭配我的Traefik配置才能使用。Traefik配置可以在这个页面获取。

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
version: '3.7'

services:
ghost:
image: ghost:3-alpine
container_name: ghost
environment:
NODE_ENV: production
volumes:
- ./ghost/content:/var/lib/ghost/content
- ./ghost/config.production.json:/var/lib/ghost/config.production.json
networks:
- proxy
restart: always
labels:
- "traefik.enable=true"
- "traefik.docker.network=proxy"
- "traefik.http.routers.ghost-secure.entrypoints=websecure"
- "traefik.http.routers.ghost-secure.rule=Host(`blog.yourdomain`)"
- "traefik.http.routers.ghost-secure.service=ghost-service"
- "traefik.http.services.ghost-service.loadbalancer.server.port=2368"

networks:
proxy:
external: true

ghost配置的重点可以在官网找到。这里我说几个我的配置中的重点。

  1. NODE_ENV:
    我的配置里面使用的是production的environment,因此我需要挂载和修改的配置文件是config.production.json
  2. 我把ghost的配置文件单独的挂载出来,里面的配置如下。里面唯一需要修改的是url,请修改为你的网站url。
    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
     {
    "url": "https://blog.yourdomain",
    "server": {
    "port": 2368,
    "host": "0.0.0.0"
    },
    "database": {
    "client": "sqlite3",
    "connection": {
    "filename": "/var/lib/ghost/content/data/ghost.db"
    }
    },
    "mail": {
    "transport": "Direct"
    },
    "logging": {
    "path": "/var/lib/ghost/content/logs/",
    "level": "info",
    "rotation": {
    "enabled": true,
    "count": 15,
    "period": "1d"
    },
    "transports": ["stdout", "file"]
    },
    "paths": {
    "contentPath": "/var/lib/ghost/content"
    }
    }
  3. (可选)使用上面的配置,如果您需要邀请其他用户,邀请函会从[email protected]发出。你可以根据自己的需求来配置不同的邮箱。例如我配置QQ企业邮箱的方法如下。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    "mail": {
    "from": "'Ghost Support' <YOUR_EMAIL>",
    "transport": "SMTP",
    "options": {
    "host": "smtp.exmail.qq.com",
    "port": 465,
    "secureConnection": true,
    "auth": {
    "user": "YOUR_EMAIL",
    "pass": "YOUR_EMAIL_PASSWORD"
    }
    }
    }

按照我的方法来做,这个ghost站应该可以轻松搭建成功。对于ghost的看法我在之前的文章说过,这里就不再重复。对于喜欢尝鲜又不喜欢折腾的朋友,ghost还不错。

下期再会