Docker 学习笔记(四) docker-compose 篇 搭建多容器 ghost博客系统

举报
小米粒-biubiubiu 发表于 2020/12/01 00:40:38 2020/12/01
【摘要】                    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


  
  1. [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
  2. % Total % Received % Xferd Average Speed Time Time Time Current
  3. Dload Upload Total Spent Left Speed
  4. 100 617 0 617 0 0 121 0 --:--:-- 0:00:05 --:--:-- 195
  5. 100 7857k 100 7857k 0 0 148k 0 0:00:52 0:00:52 --:--:-- 209k
  6. [root@localhost data]# cd /usr/local/bin/
  7. [root@localhost bin]# ll
  8. 总用量 7860
  9. -rw-r--r--. 1 root root 8045957 8 3 22:13 docker-compose
  10. [root@localhost bin]# cd docker-compose
  11. -bash: cd: docker-compose: 不是目录
  12. [root@localhost bin]# ls -l /usr/local/bin/docker-compose
  13. -rw-r--r--. 1 root root 8045957 8 3 22:13 /usr/local/bin/docker-compose
  14. [root@localhost bin]# chmod a+x /usr/local/bin/docker-compose
  15. [root@localhost bin]# ll
  16. 总用量 7860
  17. -rwxr-xr-x. 1 root root 8045957 8 3 22:13 docker-compose
  18. [root@localhost bin]# docker-compose -version
  19. docker-compose version 1.9.0, build 2585387

  
  1. [root@localhost bin]# uname -s
  2. Linux
  3. [root@localhost bin]# uname -m
  4. 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博客系统


  
  1. [root@localhost ghost]# ll
  2. 总用量 4
  3. drwxr-xr-x. 2 root root 6 8 3 22:41 data
  4. -rw-r--r--. 1 root root 562 8 3 23:03 docker-compose.yml
  5. drwxr-xr-x. 2 root root 41 8 3 23:29 ghost
  6. drwxr-xr-x. 2 root root 42 8 3 23:18 nginx
  7. [root@localhost ghost]# cd ghost/
  8. [root@localhost ghost]# ll
  9. 总用量 8
  10. -rw-r--r--. 1 root root 528 8 3 22:51 config.js
  11. -rw-r--r--. 1 root root 100 8 3 23:23 Dockerfile
  12. [root@localhost ghost]# vim Dockerfile
  13. FROM ghost
  14. COPY ./config.js /var/lib/ghost/config.js
  15. EXPOSE 2368
  16. CMD ["npm","start","--production"]
  17. [root@localhost ghost]# ll
  18. 总用量 8
  19. -rw-r--r--. 1 root root 528 8 3 22:51 config.js
  20. -rw-r--r--. 1 root root 100 8 3 23:23 Dockerfile
  21. [root@localhost ghost]# vim config.js
  22. var path = require('path'),
  23. config;
  24. config = {
  25. production:{
  26. url: 'http://mytestblog.com',
  27. mail: {},
  28. database:{
  29. client: 'mysql',
  30. connection: {
  31. host: 'db',
  32. user: 'ghost',
  33. password: 'ghost',
  34. database: 'ghost',
  35. port: '3306',
  36. charset: 'utf8'
  37. },
  38. debug: false
  39. },
  40. paths {
  41. contentPath: path.join(process.env.GHOST_CONTENT,'/')
  42. },
  43. server:{
  44. host: '0.0.0.0',
  45. port: '2368'
  46. }
  47. }
  48. };
  49. ~
  50. [root@localhost ghost]# ll
  51. 总用量 8
  52. -rw-r--r--. 1 root root 528 8 3 22:51 config.js
  53. -rw-r--r--. 1 root root 100 8 3 23:23 Dockerfile
  54. [root@localhost ghost]# cd ..
  55. [root@localhost ghost]# ll
  56. 总用量 4
  57. drwxr-xr-x. 2 root root 6 8 3 22:41 data
  58. -rw-r--r--. 1 root root 562 8 3 23:03 docker-compose.yml
  59. drwxr-xr-x. 2 root root 41 8 3 23:32 ghost
  60. drwxr-xr-x. 2 root root 42 8 3 23:18 nginx
  61. [root@localhost ghost]# cd nginx/
  62. [root@localhost nginx]# ll
  63. 总用量 8
  64. -rw-r--r--. 1 root root 60 8 3 22:52 Dockerfile
  65. -rw-r--r--. 1 root root 154 8 3 23:18 nginx.conf
  66. [root@localhost nginx]# vim Dockerfile
  67. FROM nginx
  68. COPY nginx.conf /etc/nginx/nginx.conf
  69. EXPOSE 80
  70. [root@localhost nginx]# ll
  71. 总用量 8
  72. -rw-r--r--. 1 root root 60 8 3 22:52 Dockerfile
  73. -rw-r--r--. 1 root root 154 8 3 23:18 nginx.conf
  74. [root@localhost nginx]# vim nginx.conf
  75. worker_processes 4;
  76. events {worker_connections 1024;}
  77. http {
  78. server {
  79. listen 80;
  80. location / {
  81. proxy_pass http://ghost-app:2368;
  82. }
  83. }
  84. }
  85. [root@localhost nginx]# cd ..
  86. [root@localhost ghost]# ll
  87. 总用量 4
  88. drwxr-xr-x. 2 root root 6 8 3 22:41 data
  89. -rw-r--r--. 1 root root 562 8 3 23:03 docker-compose.yml
  90. drwxr-xr-x. 2 root root 41 8 3 23:32 ghost
  91. drwxr-xr-x. 2 root root 42 8 3 23:32 nginx
  92. [root@localhost ghost]# vim docker-compose.yml
  93. version: '2'
  94. networks:
  95. ghost:
  96. services:
  97. ghost-app:
  98. build: ghost
  99. networks:
  100. - ghost
  101. depends_on:
  102. - db
  103. ports:
  104. - "2368:2368"
  105. nginx:
  106. build: nginx
  107. networks:
  108. - ghost
  109. depends_on:
  110. - ghost-app
  111. ports:
  112. - "80:80"
  113. db:
  114. image: "mysql:5.7.15"
  115. networks:
  116. - ghost
  117. environment:
  118. MYSQL_ROOT_PASSWORD: mysqlroot
  119. MYSQL_USER: ghost
  120. MYSQL_PASSWORD: ghost
  121. volumes:
  122. - $PWD/data:/var/lib/mysql
  123. ports:
  124. - "3306:3306"
  125. ~
  126. [root@localhost ghost]# ll
  127. 总用量 4
  128. drwxr-xr-x. 2 root root 6 8 3 22:41 data
  129. -rw-r--r--. 1 root root 562 8 3 23:03 docker-compose.yml
  130. drwxr-xr-x. 2 root root 41 8 3 23:32 ghost
  131. drwxr-xr-x. 2 root root 42 8 3 23:32 nginx
  132. [root@localhost ghost]# ll
  133. 总用量 4
  134. drwxr-xr-x. 2 root root 6 8 3 23:33 data
  135. -rw-r--r--. 1 root root 562 8 3 23:03 docker-compose.yml
  136. drwxr-xr-x. 2 root root 41 8 3 23:32 ghost
  137. drwxr-xr-x. 2 root root 42 8 3 23:32 nginx
  138. [root@localhost ghost]# cd data
  139. [root@localhost data]# ll
  140. 总用量 0
  141. [root@localhost data]# docker-compose build
  142. db uses an image, skipping
  143. Building ghost-app
  144. Step 1/4 : FROM ghost
  145. ---> 998ed7a41488
  146. Step 2/4 : COPY ./config.js /var/lib/ghost/config.js
  147. ---> Using cache
  148. ---> 63f0329b75a9
  149. Step 3/4 : EXPOSE 2368
  150. ---> Using cache
  151. ---> 9bbe725d825b
  152. Step 4/4 : CMD npm start --production
  153. ---> Using cache
  154. ---> 1e1cf3ac94ab
  155. Successfully built 1e1cf3ac94ab
  156. Building nginx
  157. Step 1/3 : FROM nginx
  158. ---> c82521676580
  159. Step 2/3 : COPY nginx.conf /etc/nginx/nginx.conf
  160. ---> Using cache
  161. ---> 2573d7756c50
  162. Step 3/3 : EXPOSE 80
  163. ---> Using cache
  164. ---> 7a45a147f375
  165. Successfully built 7a45a147f375
  166. [root@localhost data]# docker-compose up -d
  167. Recreating ghost_db_1
  168. Recreating ghost_ghost-app_1
  169. Recreating ghost_nginx_1
  170. [root@localhost data]# curl localhost

 

文章来源: blog.csdn.net,作者:血煞风雨城2018,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/qq_31905135/article/details/81395302

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。