欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Docker 部署 ghost + nginx + mysql

程序员文章站 2024-03-12 08:29:32
...

部署前先分层:

用户–>nginx–>ghost(app)–>mysql

创建 3 个容器

层级目录

|── data
├── docker-compose.yml
├── ghost
│   ├── Dockerfile
│   └── config.production.json
└── nginx
    ├── Dockerfile
    └── nginx.conf
ghost
Deckerfile
FROM ghost
COPY ./config.production.json /var/lib/ghost/content/config.production.json
EXPOSE 2368
#CMD ["npm","start","--production"]
config.production.json
{
    "url": "http://localhost:2368/",
    "server": {
        "port": 2368,
        "host": "0.0.0.0"
    },
    "database": {
        "client": "mysql",
        "connection": {
            "host": "db",
            "user": "ghost",
            "password": "ghost",
            "database": "ghost",
            "port": 3306,
            "charset": "utf8"
        }
    },
    "mail": {
        "transport": "Direct"
    },
    "logging": {
        "transports": [
            "file",
            "stdout"
        ]
    },
    "process": "systemd",
    "paths": {
        "contentPath": "/var/lib/ghost/content"
    }
}
nginx
Dockerfile
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
nginx.conf
worker_processes 4;
events {worker_connections 1024;}
http {
    server {
        listen 80;
        location / {
            proxy_pass http://ghost-app:2368;
        }
    }
}

data

用于存放数据库

docker-compose.yml
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-compose up
相关标签: Docker 部署