Docker 学习笔记(四) docker-compose 篇 搭建多容器 ghost博客系统
【摘要】 docker-compose搭建多容器 ghost博客系统
一.下载安装 docker-compose
[root@localhost data]# curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-$(uname -s)-...
docker-compose搭建多容器 ghost博客系统
一.下载安装 docker-compose
-
[root@localhost data]# curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-$(uname -s)-$(uname -m) > /usr/local/bin/docker-compose
-
% Total % Received % Xferd Average Speed Time Time Time Current
-
Dload Upload Total Spent Left Speed
-
100 617 0 617 0 0 121 0 --:--:-- 0:00:05 --:--:-- 195
-
100 7857k 100 7857k 0 0 148k 0 0:00:52 0:00:52 --:--:-- 209k
-
[root@localhost data]# cd /usr/local/bin/
-
[root@localhost bin]# ll
-
总用量 7860
-
-rw-r--r--. 1 root root 8045957 8月 3 22:13 docker-compose
-
[root@localhost bin]# cd docker-compose
-
-bash: cd: docker-compose: 不是目录
-
[root@localhost bin]# ls -l /usr/local/bin/docker-compose
-
-rw-r--r--. 1 root root 8045957 8月 3 22:13 /usr/local/bin/docker-compose
-
[root@localhost bin]# chmod a+x /usr/local/bin/docker-compose
-
[root@localhost bin]# ll
-
总用量 7860
-
-rwxr-xr-x. 1 root root 8045957 8月 3 22:13 docker-compose
-
[root@localhost bin]# docker-compose -version
-
docker-compose version 1.9.0, build 2585387
-
[root@localhost bin]# uname -s
-
Linux
-
[root@localhost bin]# uname -m
-
x86_64
curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-$(uname -s)-$(uname -m) > /usr/local/bin/docker-compose
注意 :$(uname -s)-$(uname -m)将 uname -s 和 uname -m输出的字符拼接到下载地址中。
二 . 搭建多容器 ghost博客系统
-
[root@localhost ghost]# ll
-
总用量 4
-
drwxr-xr-x. 2 root root 6 8月 3 22:41 data
-
-rw-r--r--. 1 root root 562 8月 3 23:03 docker-compose.yml
-
drwxr-xr-x. 2 root root 41 8月 3 23:29 ghost
-
drwxr-xr-x. 2 root root 42 8月 3 23:18 nginx
-
[root@localhost ghost]# cd ghost/
-
[root@localhost ghost]# ll
-
总用量 8
-
-rw-r--r--. 1 root root 528 8月 3 22:51 config.js
-
-rw-r--r--. 1 root root 100 8月 3 23:23 Dockerfile
-
[root@localhost ghost]# vim Dockerfile
-
FROM ghost
-
COPY ./config.js /var/lib/ghost/config.js
-
EXPOSE 2368
-
CMD ["npm","start","--production"]
-
[root@localhost ghost]# ll
-
总用量 8
-
-rw-r--r--. 1 root root 528 8月 3 22:51 config.js
-
-rw-r--r--. 1 root root 100 8月 3 23:23 Dockerfile
-
[root@localhost ghost]# vim 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'
-
}
-
}
-
};
-
~
-
[root@localhost ghost]# ll
-
总用量 8
-
-rw-r--r--. 1 root root 528 8月 3 22:51 config.js
-
-rw-r--r--. 1 root root 100 8月 3 23:23 Dockerfile
-
[root@localhost ghost]# cd ..
-
[root@localhost ghost]# ll
-
总用量 4
-
drwxr-xr-x. 2 root root 6 8月 3 22:41 data
-
-rw-r--r--. 1 root root 562 8月 3 23:03 docker-compose.yml
-
drwxr-xr-x. 2 root root 41 8月 3 23:32 ghost
-
drwxr-xr-x. 2 root root 42 8月 3 23:18 nginx
-
[root@localhost ghost]# cd nginx/
-
[root@localhost nginx]# ll
-
总用量 8
-
-rw-r--r--. 1 root root 60 8月 3 22:52 Dockerfile
-
-rw-r--r--. 1 root root 154 8月 3 23:18 nginx.conf
-
[root@localhost nginx]# vim Dockerfile
-
FROM nginx
-
COPY nginx.conf /etc/nginx/nginx.conf
-
EXPOSE 80
-
-
-
[root@localhost nginx]# ll
-
总用量 8
-
-rw-r--r--. 1 root root 60 8月 3 22:52 Dockerfile
-
-rw-r--r--. 1 root root 154 8月 3 23:18 nginx.conf
-
[root@localhost nginx]# vim nginx.conf
-
worker_processes 4;
-
events {worker_connections 1024;}
-
http {
-
server {
-
listen 80;
-
location / {
-
proxy_pass http://ghost-app:2368;
-
}
-
}
-
}
-
-
[root@localhost nginx]# cd ..
-
[root@localhost ghost]# ll
-
总用量 4
-
drwxr-xr-x. 2 root root 6 8月 3 22:41 data
-
-rw-r--r--. 1 root root 562 8月 3 23:03 docker-compose.yml
-
drwxr-xr-x. 2 root root 41 8月 3 23:32 ghost
-
drwxr-xr-x. 2 root root 42 8月 3 23:32 nginx
-
[root@localhost ghost]# vim 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"
-
-
~
-
[root@localhost ghost]# ll
-
总用量 4
-
drwxr-xr-x. 2 root root 6 8月 3 22:41 data
-
-rw-r--r--. 1 root root 562 8月 3 23:03 docker-compose.yml
-
drwxr-xr-x. 2 root root 41 8月 3 23:32 ghost
-
drwxr-xr-x. 2 root root 42 8月 3 23:32 nginx
-
-
[root@localhost ghost]# ll
-
总用量 4
-
drwxr-xr-x. 2 root root 6 8月 3 23:33 data
-
-rw-r--r--. 1 root root 562 8月 3 23:03 docker-compose.yml
-
drwxr-xr-x. 2 root root 41 8月 3 23:32 ghost
-
drwxr-xr-x. 2 root root 42 8月 3 23:32 nginx
-
[root@localhost ghost]# cd data
-
[root@localhost data]# ll
-
总用量 0
-
[root@localhost data]# docker-compose build
-
db uses an image, skipping
-
Building ghost-app
-
Step 1/4 : FROM ghost
-
---> 998ed7a41488
-
Step 2/4 : COPY ./config.js /var/lib/ghost/config.js
-
---> Using cache
-
---> 63f0329b75a9
-
Step 3/4 : EXPOSE 2368
-
---> Using cache
-
---> 9bbe725d825b
-
Step 4/4 : CMD npm start --production
-
---> Using cache
-
---> 1e1cf3ac94ab
-
Successfully built 1e1cf3ac94ab
-
Building nginx
-
Step 1/3 : FROM nginx
-
---> c82521676580
-
Step 2/3 : COPY nginx.conf /etc/nginx/nginx.conf
-
---> Using cache
-
---> 2573d7756c50
-
Step 3/3 : EXPOSE 80
-
---> Using cache
-
---> 7a45a147f375
-
Successfully built 7a45a147f375
-
[root@localhost data]# docker-compose up -d
-
Recreating ghost_db_1
-
Recreating ghost_ghost-app_1
-
Recreating ghost_nginx_1
-
[root@localhost data]# curl localhost
文章来源: blog.csdn.net,作者:血煞风雨城2018,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq_31905135/article/details/81395302
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)