『中級篇』Docker compose 部署一個復雜的應用(41)

原創(chuàng)文章,歡迎轉載媳维。轉載請注明:轉載自IT人故事會裕便,謝謝!
原文鏈接地址:『中級篇』Docker compose 部署一個復雜的應用(41)

今天部署一個復雜的application餐抢。源碼地址:https://github.com/limingios/docker中的No.4中的example-voting-app。里面包括5個模塊低匙。

個人主頁:idig.com

Voting App

暴露給外邊訪問的旷痕,投票使用,里面有對應的候選人的選項顽冶。是個python項目欺抗。這個將投票結果放入redis中,在現(xiàn)實中投票的人都比較多强重,為了方便存儲直接連通的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數(shù)據(jù)庫的結果圾亏。

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數(shù)據(jù)庫,是個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官網(wǎng)介紹(四)
  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. 鏡像的發(fā)布(18)
  19. Dockerfile實戰(zhàn)(19)
  20. 容器的操作(20)
  21. Dockerfile實戰(zhàn)CMD和ENTRTYPOINT的配合(21)
  22. 容器的資源限制(22)
  23. docker網(wǎng)絡(23)
  24. docker學習必會網(wǎng)絡基礎(24)
  25. Linux網(wǎng)絡命名空間(25)
  26. Docker Bridge詳解(26)
  27. 容器之間的Link(27)
  28. 容器的端口映射(28)
  29. 容器網(wǎng)絡之host和none(29)
  30. 多容器復雜應用的部署(30)
  31. overlay網(wǎng)絡和etcd實現(xiàn)多機的容器通信(31)
  32. docker的數(shù)據(jù)持久化存儲和數(shù)據(jù)共享(32)
  33. windows下vagrant 通過SecureCRT連接centos7(33)
  34. 數(shù)據(jù)持久化之Data Volume(34)
  35. 數(shù)據(jù)持久化之bind Mounting(35)
  36. docker 使用bind Mounting實戰(zhàn)(36)
  37. docker容器安裝wordpress(37)
  38. docker Compose到底是什么(38)
  39. Docker Compose的安裝和基本使用(39)
  40. Docker 水平擴展和負載均衡(40)
    image
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市非竿,隨后出現(xiàn)的幾起案子蜕着,更是在濱河造成了極大的恐慌,老刑警劉巖红柱,帶你破解...
    沈念sama閱讀 210,978評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件承匣,死亡現(xiàn)場離奇詭異,居然都是意外死亡锤悄,警方通過查閱死者的電腦和手機韧骗,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,954評論 2 384
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來零聚,“玉大人袍暴,你說我怎么就攤上這事×ブⅲ” “怎么了政模?”我有些...
    開封第一講書人閱讀 156,623評論 0 345
  • 文/不壞的土叔 我叫張陵,是天一觀的道長蚂会。 經(jīng)常有香客問我淋样,道長,這世上最難降的妖魔是什么颂龙? 我笑而不...
    開封第一講書人閱讀 56,324評論 1 282
  • 正文 為了忘掉前任习蓬,我火速辦了婚禮,結果婚禮上措嵌,老公的妹妹穿的比我還像新娘躲叼。我一直安慰自己,他們只是感情好企巢,可當我...
    茶點故事閱讀 65,390評論 5 384
  • 文/花漫 我一把揭開白布枫慷。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪或听。 梳的紋絲不亂的頭發(fā)上探孝,一...
    開封第一講書人閱讀 49,741評論 1 289
  • 那天,我揣著相機與錄音誉裆,去河邊找鬼顿颅。 笑死,一個胖子當著我的面吹牛足丢,可吹牛的內容都是我干的粱腻。 我是一名探鬼主播,決...
    沈念sama閱讀 38,892評論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼斩跌,長吁一口氣:“原來是場噩夢啊……” “哼绍些!你這毒婦竟也來了?” 一聲冷哼從身側響起耀鸦,我...
    開封第一講書人閱讀 37,655評論 0 266
  • 序言:老撾萬榮一對情侶失蹤柬批,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后袖订,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體氮帐,經(jīng)...
    沈念sama閱讀 44,104評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 36,451評論 2 325
  • 正文 我和宋清朗相戀三年著角,在試婚紗的時候發(fā)現(xiàn)自己被綠了揪漩。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,569評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡吏口,死狀恐怖奄容,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情产徊,我是刑警寧澤昂勒,帶...
    沈念sama閱讀 34,254評論 4 328
  • 正文 年R本政府宣布,位于F島的核電站舟铜,受9級特大地震影響戈盈,放射性物質發(fā)生泄漏。R本人自食惡果不足惜谆刨,卻給世界環(huán)境...
    茶點故事閱讀 39,834評論 3 312
  • 文/蒙蒙 一塘娶、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧痊夭,春花似錦刁岸、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,725評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽迫横。三九已至,卻和暖如春酝碳,著一層夾襖步出監(jiān)牢的瞬間矾踱,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,950評論 1 264
  • 我被黑心中介騙來泰國打工疏哗, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留呛讲,地道東北人。 一個月前我還...
    沈念sama閱讀 46,260評論 2 360
  • 正文 我出身青樓返奉,卻偏偏與公主長得像圣蝎,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子衡瓶,可洞房花燭夜當晚...
    茶點故事閱讀 43,446評論 2 348

推薦閱讀更多精彩內容