2 min read 总阅读量: 加载中...

Docker搭建Ghost博客

这是一篇备份文章记录使用Dockerfile搭建ghost博客的脚本。

这是一篇备份文章记录使用Dockerfile搭建ghost博客的脚本。

01. Dockerfile脚本内容

搭建Ghost博客Dockerfile.yaml脚本内容如下:

version: '3.1'

services:

  ghost:
    image: ghost
    restart: always
    ports:
      - 8080:2368 #转发端口,2368为ghost启动端口
    volumes:
         - /root/ghost/content:/var/lib/ghost/content 
    environment:
      # see https://ghost.org/docs/config/#configuration-options
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: 数据库密码
      database__connection__database: ghost
      # this url value is just an example, and is likely wrong for your environment!
      url: https://leonhe.cn #访问域名
      # contrary to the default mentioned in the linked documentation, this image defaults to NODE_ENV=production (so development mode needs to be explicitly specified if desired)
      NODE_ENV: production

  db:
    image: mysql:8.0
    restart: always
    volumes:
      - /root/mysql:/var/lib/mysql 
    environment:
      MYSQL_ROOT_PASSWORD: [数据库密码]

volumes为容器内容的映射目录,根据实际需求进行修改,这里ghost内容被映射到了/root/ghost/content,Mysql数据被映射到了/root/mysql 目录下,备份好这两目录下的内容就能避免内容丢失。

02. Docker file 使用命令

进入创建的dockerfile.yaml目录后可以执行以下命令进行对应的操作命令:

- docker-compose up -d #启动容器
- docker-compose down #暂停容器
- docker-compose restart #重启容器

03. 后记

Docker现在搭建各种服务是真方便,只要写好Dockerfile.yaml配置文件后通过命令行启动/停止/重启服务就行了,对于运维来说完全是可以一劳永逸的东西。

04. Email设置

environment:  
# see [https://ghost.org/docs/config/#configuration-options]
……….  
#Email  
mail__transport: SMTP  
mail__options__host: SMTP Server
mail__options__port: SMTP端口 
mail__options__auth__user: 登录用户名
mail__options__auth__pass: 认证密码
mail__from: Notification<显示邮箱地址>