『中级篇』Docker compose 部署一个复杂的应用(41)

原创文章,欢迎转载。转载请注明:转载自IT人故事会,谢谢!
原文链接地址:『中级篇』Docker compose 部署一个复杂的应用(41)

今天部署一个复杂的application。源码地址:https://github.com/limingios/docker中的No.4中的example-voting-app。里面包括5个模块。

个人主页:idig.com

Voting App

暴露给外边访问的,投票使用,里面有对应的候选人的选项。是个python项目。这个将投票结果放入redis中,在现实中投票的人都比较多,为了方便存储直接连通的redis内存中。

Dockfile

# 使用python2.7的镜像
FROM python:2.7

# 设置一个application的目录
WORKDIR /app

# 文件依赖,安装指定的目录,通过pip进行安装
ADD requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt

# Copy our code from the current folder to /app inside the container
ADD . /app

# 暴露端口80
EXPOSE 80 

# 启动容器命令
CMD ["python", "app.py"]

Results App

暴露给外边访问的,实时的显示候选人的得票情况。是个node js项目。直接取PG数据库的结果。

Dockfile

FROM node:0.10

RUN mkdir /app
WORKDIR /app

ADD package.json /app/package.json
RUN npm install && npm ls
RUN mv /app/node_modules /node_modules

ADD . /app

ENV PORT 80
EXPOSE 80

CMD ["node", "server.js"]
worker

读取redis效果,并将结果记录到PG数据库,是个java项目。

image.png

Dockfile

FROM java:7

RUN apt-get update -qq && apt-get install -y maven && apt-get clean

WORKDIR /code

ADD pom.xml /code/pom.xml
RUN ["mvn", "dependency:resolve"]
RUN ["mvn", "verify"]

# Adding source, compile and package into a fat jar
ADD src /code/src
RUN ["mvn", "package"]

CMD ["/usr/lib/jvm/java-7-openjdk-amd64/bin/java", "-jar", "target/worker-jar-with-dependencies.jar"]
整合docker-compose.yml

里面配置文件包括5个项目:voting-app,result-app,worker,redis,db

docker-compose.yml

version: "3"

services:
  voting-app:
    build: ./voting-app/.
    volumes:
     - ./voting-app:/app
    ports:
      - "5000:80"
    links:
      - redis
    networks:
      - front-tier
      - back-tier

  result-app:
    build: ./result-app/.
    volumes:
      - ./result-app:/app
    ports:
      - "5001:80"
    links:
      - db
    networks:
      - front-tier
      - back-tier

  worker:
    build: ./worker
    links:
      - db
      - redis
    networks:
      - back-tier

  redis:
    image: redis
    ports: ["6379"]
    networks:
      - back-tier

  db:
    image: postgres:9.4
    volumes:
      - "db-data:/var/lib/postgresql/data"
    networks:
      - back-tier

volumes:
  db-data:

networks:
  front-tier:
  back-tier:
docker-compose 一键部署

到docker-compose.yml目录

sudo service docker restart
sudo docker-compose up
#查看eth1的ip地址 映射了2个端口5000和5001
ip a

PS:有老铁在安装worker项目的maven的时候报插件错误

[INFO] Scanning for projects...
Downloading: [http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom](http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom)
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-clean-plugin:2.4.1: Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1
Downloading: [http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.3.1/maven-install-plugin-2.3.1.pom](http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.3.1/maven-install-plugin-2.3.1.pom)
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-install-plugin:2.3.1: Plugin org.apache.maven.plugins:maven-install-plugin:2.3.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-install-plugin:jar:2.3.1
Downloading: [http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-deploy-plugin/2.5/maven-deploy-plugin-2.5.pom](http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-deploy-plugin/2.5/maven-deploy-plugin-2.5.pom)
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-deploy-plugin:2.5: Plugin org.apache.maven.plugins:maven-deploy-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-deploy-plugin:jar:2.5
Downloading: [http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-site-plugin/2.0.1/maven-site-plugin-2.0.1.pom](http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-site-plugin/2.0.1/maven-site-plugin-2.0.1.pom)
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-site-plugin:2.0.1: Plugin org.apache.maven.plugins:maven-site-plugin:2.0.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-site-plugin:jar:2.0.1
Downloading: [http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-antrun-plugin/1.3/maven-antrun-plugin-1.3.pom](http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-antrun-plugin/1.3/maven-antrun-plugin-1.3.pom)
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-antrun-plugin:1.3: Plugin org.apache.maven.plugins:maven-antrun-plugin:1.3 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-antrun-plugin:jar:1.3
Downloading: [http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-assembly-plugin/2.2-beta-5/maven-assembly-plugin-2.2-beta-5.pom](http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-assembly-plugin/2.2-beta-5/maven-assembly-plugin-2.2-beta-5.pom)
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5: Plugin org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-assembly-plugin:jar:2.2-beta-5
Downloading: [http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.1/maven-dependency-plugin-2.1.pom](http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.1/maven-dependency-plugin-2.1.pom)
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-dependency-plugin:2.1: Plugin org.apache.maven.plugins:maven-dependency-plugin:2.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-dependency-plugin:jar:2.1
Downloading: [http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-release-plugin/2.0/maven-release-plugin-2.0.pom](http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-release-plugin/2.0/maven-release-plugin-2.0.pom)
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-release-plugin:2.0: Plugin org.apache.maven.plugins:maven-release-plugin:2.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-release-plugin:jar:2.0
Downloading: [http://repo1.maven.org/maven2/org/codehaus/mojo/maven-metadata.xml](http://repo1.maven.org/maven2/org/codehaus/mojo/maven-metadata.xml)
Downloading: [http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-metadata.xml](http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-metadata.xml)
[WARNING] Could not transfer metadata org.apache.maven.plugins/maven-metadata.xml from/to central ([http://repo1.maven.org/maven2](http://repo1.maven.org/maven2)): Error transferring file: Connection timed out: connect
[WARNING] Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/to central ([http://repo1.maven.org/maven2](http://repo1.maven.org/maven2)): Error transferring file: Connection timed out: connect
Downloading: [http://repo1.maven.org/maven2/org/codehaus/mojo/maven-metadata.xml](http://repo1.maven.org/maven2/org/codehaus/mojo/maven-metadata.xml)
Downloading: [http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-metadata.xml](http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-metadata.xml)
[WARNING] Could not transfer metadata org.apache.maven.plugins/maven-metadata.xml from/to central ([http://repo1.maven.org/maven2](http://repo1.maven.org/maven2)): Error transferring file: Connection timed out: connect
[WARNING] Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/to central ([http://repo1.maven.org/maven2](http://repo1.maven.org/maven2)): Error transferring file: Connection timed out: connect
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3:30.786s
[INFO] Finished at: Sun Jul 08 15:55:29 CST 2012
[INFO] Final Memory: 2M/121M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'archetype' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (D:\project\.mave_repo\repo), central ([http://repo1.maven.org/maven2](http://repo1.maven.org/maven2))] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] [http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException](http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException)

我更新了worker目录下的Dockerfile文件,使用阿里云maven仓库地址覆盖了原来的maven地址。我是先找到docker所在的容器,通过install maven的时候maven的安装路径:/usr/share/maven/conf/ ,然后将本地的settings.xml覆盖原来的地址就可以解决了。


往期精彩
  1. docker导学(一)
  2. 容器的技术概述(二)
  3. docker的魅力初体验-5分钟安装wordpress不走弯路(三)
  4. docker官网介绍(四)
  5. 如何在mac上安装docker(五)
  6. 如何在window上安装docker(六)
  7. 如何在mac上通过vagrant安装虚拟机(七)
  8. 如何在window上通过vagrant安装虚拟机(八)
  9. docker-Machine的本地使用(九)
  10. docker-Machine的本地使用(十)
  11. 在linux/mac下通过Docker-Machine在阿里云上的使用(11)
  12. docker架构和底层技术(12)
  13. docker Image概述(13)
  14. 手动建立一个base Image(14)
  15. 什么是Container(15)
  16. 构建自己的Docker镜像(16)
  17. Dockerfile详解(17)
  18. 镜像的发布(18)
  19. Dockerfile实战(19)
  20. 容器的操作(20)
  21. Dockerfile实战CMD和ENTRTYPOINT的配合(21)
  22. 容器的资源限制(22)
  23. docker网络(23)
  24. docker学习必会网络基础(24)
  25. Linux网络命名空间(25)
  26. Docker Bridge详解(26)
  27. 容器之间的Link(27)
  28. 容器的端口映射(28)
  29. 容器网络之host和none(29)
  30. 多容器复杂应用的部署(30)
  31. overlay网络和etcd实现多机的容器通信(31)
  32. docker的数据持久化存储和数据共享(32)
  33. windows下vagrant 通过SecureCRT连接centos7(33)
  34. 数据持久化之Data Volume(34)
  35. 数据持久化之bind Mounting(35)
  36. docker 使用bind Mounting实战(36)
  37. docker容器安装wordpress(37)
  38. docker Compose到底是什么(38)
  39. Docker Compose的安装和基本使用(39)
  40. Docker 水平扩展和负载均衡(40)
    image
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,504评论 4 365
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,898评论 1 300
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 110,218评论 0 248
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,322评论 0 214
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,693评论 3 290
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,812评论 1 223
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,010评论 2 315
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,747评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,476评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,700评论 2 251
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,190评论 1 262
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,541评论 3 258
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,206评论 3 240
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,129评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,903评论 0 199
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,894评论 2 283
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,748评论 2 274

推荐阅读更多精彩内容