步骤3:
准备一个配置文件
用之前准备的一个文件拷贝过来,可以查看原来的config配置文件的内容:
步骤4:
compose实战:
步骤1:
步骤2:
vi Dockerfile,编辑此文件,说明以下三行的意思:
FROM ghost #直接调用ghost
COPY ./config.js /var/lib/ghost/config.js #拷贝本地的一个config文件
EXPOSE 2368 #开放端口2368
CMD ["npm","start","--production"] #执行一个命令npm,直接启动
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:
# see https://ghost.org/docs/config/#configuration-options
database__client: mysql
database__connection__host: db
database__connection__user: root
database__connection__password: example
database__connection__database: ghost
# this url value is just an example, and is likely wrong for your environment!
# url: http://localhost:8080
# contrary to the default mentioned in the linked documentation, this image defaults to NODE_ENV=production (so development mode needs to be explicitly specified if desired)
#NODE_ENV: development
db:
image: mysql:5.7
restart: always
networks:
- ghost
volumes:
- $PWD/data:/var/lib/mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: example
FROM ghost:3-alpine
EXPOSE 2368
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
worker_processes 4;
events {
worker_connections 1024;
}
http {
server {
listen 80;
location / {
proxy_pass http://ghost-app:2368;
}
}
}
dokcer-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/libmysql
ports:
- "3306:3306"
上课前可以将本节课的所有代码先clone下来。
git clone https://github.com/cy101/ghost_config.git
nginx 配置
worker_processes 4;
events {worker_connections 1024;}
http {
server {
listen 80;
location / {
proxy_pass http://ghost-app:2368;
}
}
}
config.js 文件复制
var path = require('path'),
config;
config = {
production: {
url: 'http://mytestblog.com',
mail: {},
database: {
client: 'mysql',
connection: {
host: 'db',
user: 'ghost',
database: 'ghost',
port: '3306',
charset: 'utf-8'
},
debug: false
},
paths: {
contentPath: path.join(process.env.GHOST_CONTENT,'/')
},
server: {
host: '0.0.0.0',
port: '2368'
}
}
};
module.exports =config;
创建Dockerfile文件
nginx: http层,接入层
ghost app: 业务逻辑层
mysql: 数据层
Ghost_Demo_docker-compose\docker-compose.yml:
version: "3" networks: ghost: # Networks to join services: ghost-app: image: ghost restart: always networks: - ghost depends_on: - db ports: - "2368:2368" environment: # see https://docs.ghost.org/docs/config#section-running-ghost-with-config-env-variables database__client: mysql database__connection__host: db database__connection__user: ghost database__connection__password: ghost database__connection__database: ghost nginx: build: nginx restart: always # the container always restarts networks: - ghost depends_on: - ghost-app ports: - "80:80" db: image: "mariadb" restart: always networks: - ghost environment: MYSQL_ROOT_PASSWORD: mysqlroot MYSQL_DATABASE: ghost MYSQL_USER: ghost MYSQL_PASSWORD: ghost volumes: - $PWD/data:/var/lib/mysql ports: - "3306:3306"
Ghost_Demo_docker-compose\nginx\nginx.conf:
worker_processes 4; events {worker_connections 1024;} http { server { listen 80; location / { proxy_pass http://ghost-app:2368; } } }
Ghost_Demo_docker-compose\nginx\Dockerfile:
FROM nginx COPY nginx.conf /etc/nginx/nginx.conf EXPOSE 80
docker-compose-yaml:
ghost-app: build: ghost depends_on: - db ports - "2368:2368" nginx: build: nginx ports: - "80:80" depends_on: - ghost-app db: image: "mysql:5.7.15"
Docker- compose
其他同学做的项目,放在了 github
docker-compose up -d:以守护进程的方式将容器运行起来
docer-compose stop:停掉所有的容器
docker-compose rm:删除所有的容器
docker-compose build:已有容器时的重新构建
修改ngnix.conf :有些空格应该是下划线
前面的yaml中 数据卷的映射 :/var/lib/mysql
开始构建: docker-compose up -d
注意:上一条笔记中的 networks: -ghost 改成 ghost:
5.在最外层的ghost路径下创建构建的文件:touch docker-compose.yml
5.在最外层的ghost路径下创建构建的文件:touch docker-compose.yml
4.在ngnix中配置镜像,首先还是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
}
}
}
1.mkdir ghost
cd ghost
2.mkdir ghost
mkdir nginx
mkdir data
3.在ghost/ghost 中创建Dockerfile
FROM ghost
COPY ./config.js /var/lib/ghost/config.js
EXPOSE 2368
CMD ["nmp", "start", "--production"]
还有一个config.js 文件见截图
docker-compose.yaml
docker-compose up -d:以守护进程的方式将容器运行起来
docer-compose stop:停掉所有的容器
docker-compose rm:删除所有的容器
docker-compose build:已有容器时的重新构建
docker-compose改错
docker-compose (v2)
内容不能少于5个字!
内容不能少于5个字!