问答详情
源自:6-3 compose实战

【6-3 compose实战】2022-03-10成功运行说明(1)各个镜像的内容和配置文件的内容

首先,对前面评论和提问题的小伙伴表示感谢,他们给我了很多提示和信息。

另外,要说明的是,因为大家都是初学者,老师给的例子没有指定ghost的版本,所以拉取的会是最新版本,所以很有可能我下面的说明随着ghost新的版本更新也会有一些问题,无法运行。

但是现在测试是没有问题的,我完全跑起来了,也写下来给后来的小伙伴们分享。


首先是ghost镜像的Dockerfile内容:

FROM ghost:3-alpine

COPY ./config.js /var/lib/ghost/content/config.js

EXPOSE 2368

接下来是配置文件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',

            port: '3306',

            charset: 'utf8'

        },

        debug: false

    },

    paths: {

        contentPath: path.join(process.env.GHOST_CONTENT, '/')

    },

    server: {

        host: '0.0.0.0',

        port: '2368'

    }

  }

};

 

module.exports = config;

nginx镜像文件内容:

FROM nginx

COPY nginx.conf /etc/nginx/nginx.conf

EXPOSE 80

nginx配置文件内容:

worker_processes 4;

events {

    worker_connections 1024;

}

http {

    server {

        listen 80;

        location / {

            proxy_pass http://ghost-app:2368;

        }

    }

}

docker-compose.yml文件的内容:

version: '3.1'

networks:

  ghost:

services:

  nginx:

    build: nginx

    networks:

      - ghost

    ports:

      - "80:80"

    depends_on:

      - ghost-app

  ghost-app:

    build: ghost

    networks:

      - ghost

    depends_on:

      - db

    restart: always

    ports:

      - "2368:2368"

    environment:

      database__client: mysql

      database__connection__host: db

      database__connection__user: ghost

      database__connection__password: ghost

      database__connection__database: ghost

  db:

    image: mysql:5.7.15

    restart: always

    networks:

      - ghost

    volumes:

      - $PWD/data:/var/lib/mysql

    ports:

      - "3306:3306"

    environment:

      MYSQL_ROOT_PASSWORD: example

      MYSQL_USER: ghost

      MYSQL_PASSWORD: ghost


提问者:山青媛娴 2022-03-10 14:35

个回答