9. docker-compose 手动编写搭建ghost

2022-09-11 13:10:27 浏览数 (1)

以root用户操作下载安装docker-compose

代码语言:javascript复制
curl -L https://get.daocloud.io/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

注释:su 切换root账户,如密码遗忘,sudo passwd root 修改密码。

目录结构

代码语言:javascript复制
└── blog
    ├── data
    ├── docker-compose.yml
    ├── ghost
    │   ├── config.js
    │   └── Dockerfile
    └── nginx
        ├── Dockerfile
        └── nginx.conf

data/ghost目录的config.js

代码语言:javascript复制
var path = require('path'),
config;

config = {
  production: {
    url: 'http://myb.com',
    mail: {},
    database: {
      client: 'mysql',
      connection: {
        host: 'db',
        user: 'ghost',
        password: 'ghost',
        database: 'ghost',
        port: '3306',
        charset: 'utf8'
      }
      debug: false
    },
    paths: {
      contentPath: path.join(process.env.GHOST_CONTENT,'/')
    },
    server: {
      host: '0.0.0.0',
      port: '2368'
    }
  }
};

data/ghost目录的Dockerfile

代码语言:javascript复制
FROM ghost
COPY config.js /var/lib/ghost/content/config.js
EXPOSE 2368

data/nginx目录的nginx.conf

代码语言:javascript复制
worker_processes 4;

events {

   worker_connections 1024;
}

http{

   server {

      listen 80;

      location / {

           proxy_pass http://ghost-app:2368;

        }
   }

}

data/nginx目录的Dockerfile

代码语言:javascript复制
FROM nginx
COPY nginx.conf /ect/nginx/nginx.conf
EXPOSE 80

data/docker-compose.yml

代码语言:javascript复制
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"

执行构建:

代码语言:javascript复制
docker-compose up -d

0 人点赞