学习笔记
安装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