4、docker compose
作者:互联网
4、docker compose
安装Docker Compose
安装Docker Compose
[root@VM-0-12-centos bin]# sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 633 100 633 0 0 656 0 --:--:-- --:--:-- --:--:-- 655
100 11.6M 100 11.6M 0 0 42532 0 0:04:48 0:04:48 --:--:-- 39272
为脚本添加执行权限
[root@VM-0-12-centos bin]# chmod a+x /usr/local/bin/docker-compose
检查是否可用
[root@VM-0-12-centos bin]# docker-compose -v
docker-compose version 1.26.2, build eefe0d31
example
1、先创建3个目录,分别对应ghost app、nginx、data(data用于挂载mysql中的数据)
[root@VM-0-12-centos compose-example]# mkdir nginx
[root@VM-0-12-centos compose-example]# mkdir data
[root@VM-0-12-centos compose-example]# mkdir ghost
[root@VM-0-12-centos compose-example]# ls
data ghost nginx
2、在ghost中写好config.js文件
[root@VM-0-12-centos ghost]# cat config.js
var path = require('path'),config;
config = {
production: {
url: 'http://mytestblog.com'
mail: {},
database: {
client: 'mysql',
connection: {
host: 'db',
user: 'ghost',
password: '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;
3、准备好Dockerfile文件
[root@VM-0-12-centos ghost]# cat Dockerfile
FROM ghost
COPY ./config.js /var/lib/ghost/config.js
EXPOSE 2368
CMD ["npm", "start", "--production"]
4、配置好nginx的Dockerfile文件
[root@VM-0-12-centos ghost]# cd ../nginx/
[root@VM-0-12-centos nginx]# cat Dockerfile
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
5、配置nginx.conf
[root@VM-0-12-centos nginx]# cat nginx.conf
worker processes 4;
events {worker connections 1024}
http {
server {
listen 80;
location / {
proxy pass http://ghost-app:2368
}
}
}
6、配置好docker-compose.yml配置文件
[root@VM-0-12-centos compose-example]# cat 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_PORT_PASSWORD: mysqlroot
MYSQL_USER: ghost
MYSQL_PASSWORD: ghost
volumes:
- /root/mysql-data:/var/libmysql
ports:
- "3306:3306"
7、最终配置好的结果
[root@VM-0-12-centos compose-example]# ls
data docker-compose.yml ghost nginx
docker-compose常用命令
标签:ghost,compose,centos,nginx,12,docker,root 来源: https://blog.csdn.net/weixin_36020178/article/details/117201079