搭建docker版Ghost CMS

DNXRZL
2022年08月20日 · 阅读 814
面向小白教程,引导入门,不懂请留言
docker Ghost版本:目前最新版(ghost:5.10.1)
准备已安装好 docker 和 docker-compose 的linux系统
相关目录准备
在当前用户目录下创建以下文件夹和文件
进入当前用户目录:
cd ~
创建相关文件夹并进入:
mkdir docker_app && cd docker_app && mkdir ghost && cd ghost
创建 docker-compose.yml 和 config.production.json :
touch {docker-compose.yml,config.production.json}
编写 docker-compose.yml
为了方便以后可能多次安装,不采用命令安装,而是写成脚本
version: '3'
services:
ghost:
image: ghost:5.10.1
container_name: ghost
ports:
# 宿主机与容器端口映射,8079宿主机端口,另一个是容器的,访问时,宿主机公网 IP:8079/
- "8079:2368"
volumes:
# 生产模式下的ghost配置文件映射目录(ghost相关配置写在这里面,比如数据库、邮箱...)
- /root/docker_app/ghost/config.production.json:/var/lib/ghost/config.production.json
# ghost 相关数据目录从容器映射到宿主机
- /root/docker_app/ghost/content:/var/lib/ghost/content
environment:
# 以生产模式运行
- NODE_ENV=production
restart: unless-stopped
config.production.json 配置文件配置
{
"url": "http://宿主机公网IP:8079/",
"server": {
"port": 2368,
"host": "0.0.0.0"
},
"database": {
"client": "sqlite3",
"connection": {
"filename": "content/data/ghost.db"
},
"useNullAsDefault": true,
"debug": false
},
"logging": {
"transports": [
"file",
"stdout"
]
},
"process": "systemd",
"paths": {
"contentPath": "/var/lib/ghost/content"
}
}
注意: 这里的配置,只是一些基本配置,但可以运行起来,数据库为了方便用了sqllite,当然也可以改成mysql,对于更多的配置项,例如邮箱,可以参考官方文档配置项
创建ghost容器,启动ghost
两个文件配置好后,输入下面两个命令,就可以启动ghost了
cd ~/docker_app/ghost
docker-compose up -d
如何通过域名访问?
我们目前还是通过宿主机公网IP:端口号(http://ip:8079)来访问,那如何通过域名且不加端口号来访问呢?(之所以不直接映射到宿主机的80端口,是因为我们不能让这一个网站占用了这唯一的80端口,毕竟还有可能搭建其他网站)
这里就要用到反向代理了,好了点到为止…