用docker-compose搭建ghost 的学习笔记及其遇到的问题

学习笔记

安装docker-compose

    //下载并安装docker-compose
    curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-$(uname -s)-$(uname -m) > /usr/local/bin/docker-compose
     ll /usr/local/bin/docker-compose 
    //赋予权限
    chmod a+x /usr/local/bin/docker-compose

    docker-compose --version

注意:报错curl: (6) Could not resolve host: github-releases.githubusercontent.com;解决办法

ghost文件结构及配置

  • docker/ghost/docker-compose.yum

      version: '2'
    
      networks:
        ghost:
    
      services:
        ghost-app:
          build: ghost
          networks:
            - ghost
          depends_on:
            - db
          ports:
            - "2368:2368"
    
        nginx:
          build: nginx
          networks:
            - ghost
          depends_on:
            - ghost-app
          ports:
            - "80:80"
        
        db:
          image: "mysql:5.7.15"
          networks:
            - ghost
          environment:
            MYSQL_ROOT_PASSWORD: mysqlroot
            MYSQL_USER: ghost
            MYSQL_PASSWORD: ghost
          volumes:
            - $PWD/data:/var/lib/mysql
          ports:
            - "3306:3306"
    
  • docker/ghost/ghost/Dockerfile

      FROM ghost
      COPY ./config.js /var/lib/ghost/config.js
      EXPOSE 2368
      #CMD ["npm", "start", "--production"]
    

注意:最新的ghost 需要禁掉 CMD [“npm”, “start”, “–production”]

  • docker/ghost/ghost/config.js

      var path = require('path'),
      config;
    
      config = {
        production:{
          url: 'http://mytestblog.com',
          mail: {},
          database: {
            client: 'mysql',
            connection: {
              host: 'db',
              user: 'ghost',
              password: 'ghost',
              database: 'ghost',
              prot: '3306',
              charset: 'utf8'
         },
         debug: false
        },
        paths: {
          contenPath: path.join(process.env.GHOST_CONTENT,'/')
        },
        server: {
          host: '0.0.0.0',
          port: '2368'
        }
       }
      };
    
      module.exports = config;
    
  • docker/ghost/nginx/Dockerfile

      worker_processes 4;
      events {worker_connections 1024;}
      http {
         server {
             listen 80;
             location /{
                 proxy_pass http://ghost-app:2368;
             }
         }
      }
    
  • docker/ghost/nginx/nginx.conf

      worker_processes 4;
      events {worker_connections 1024;}
      http {
         server {
             listen 80;
             location /{
                 proxy_pass http://ghost-app:2368;
             }
         }
      }
    
  • docker/ghost/data
    此为空文件夹

遇到的问题

    docker-compose ps 状态码错误
     Exit 254 
    docker-compose logs ghost-app

    ghost-app_1  | npm ERR! code ENOENT
    ghost-app_1  | npm ERR! syscall open
    ghost-app_1  | npm ERR! path /var/lib/ghost/package.json
    ghost-app_1  | npm ERR! errno -2
    ghost-app_1  | npm ERR! enoent ENOENT: no such file or directory, open '/var/lib/ghost/package.json'

如下图所示

解决办法

docker/ghost/ghost/Dockerfile 下

CMD [“npm”, “start”, “–production”] 删除

停止docker-compose 服务

    docker-compose stop

删除原有的容器

    docker-compose rm

重新构建

    docker-compose build

重新启动服务即可

    docker-compose up -d

查看相关容器

    docker-compose ps
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值