『中級(jí)篇』Docker compose 部署一個(gè)復(fù)雜的應(yīng)用(41)

原創(chuàng)文章,歡迎轉(zhuǎn)載。轉(zhuǎn)載請(qǐng)注明:轉(zhuǎn)載自IT人故事會(huì),謝謝!
原文鏈接地址:『中級(jí)篇』Docker compose 部署一個(gè)復(fù)雜的應(yīng)用(41)

今天部署一個(gè)復(fù)雜的application。源碼地址:https://github.com/limingios/docker中的No.4中的example-voting-app。里面包括5個(gè)模塊。

個(gè)人主頁(yè):idig.com

Voting App

暴露給外邊訪(fǎng)問(wèn)的,投票使用,里面有對(duì)應(yīng)的候選人的選項(xiàng)。是個(gè)python項(xiàng)目。這個(gè)將投票結(jié)果放入redis中,在現(xiàn)實(shí)中投票的人都比較多,為了方便存儲(chǔ)直接連通的redis內(nèi)存中。

Dockfile

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

# 設(shè)置一個(gè)application的目錄
WORKDIR /app

# 文件依賴(lài),安裝指定的目錄,通過(guò)pip進(jìn)行安裝
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 

# 啟動(dòng)容器命令
CMD ["python", "app.py"]

Results App

暴露給外邊訪(fǎng)問(wèn)的,實(shí)時(shí)的顯示候選人的得票情況。是個(gè)node js項(xiàng)目。直接取PG數(shù)據(jù)庫(kù)的結(jié)果。

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效果,并將結(jié)果記錄到PG數(shù)據(jù)庫(kù),是個(gè)java項(xiàng)目。

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個(gè)項(xiàng)目: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個(gè)端口5000和5001
ip a

PS:有老鐵在安裝worker項(xiàng)目的maven的時(shí)候報(bào)插件錯(cuò)誤

[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倉(cāng)庫(kù)地址覆蓋了原來(lái)的maven地址。我是先找到docker所在的容器,通過(guò)install maven的時(shí)候maven的安裝路徑:/usr/share/maven/conf/ ,然后將本地的settings.xml覆蓋原來(lái)的地址就可以解決了。


往期精彩
  1. docker導(dǎo)學(xué)(一)
  2. 容器的技術(shù)概述(二)
  3. docker的魅力初體驗(yàn)-5分鐘安裝wordpress不走彎路(三)
  4. docker官網(wǎng)介紹(四)
  5. 如何在mac上安裝docker(五)
  6. 如何在window上安裝docker(六)
  7. 如何在mac上通過(guò)vagrant安裝虛擬機(jī)(七)
  8. 如何在window上通過(guò)vagrant安裝虛擬機(jī)(八)
  9. docker-Machine的本地使用(九)
  10. docker-Machine的本地使用(十)
  11. 在linux/mac下通過(guò)Docker-Machine在阿里云上的使用(11)
  12. docker架構(gòu)和底層技術(shù)(12)
  13. docker Image概述(13)
  14. 手動(dòng)建立一個(gè)base Image(14)
  15. 什么是Container(15)
  16. 構(gòu)建自己的Docker鏡像(16)
  17. Dockerfile詳解(17)
  18. 鏡像的發(fā)布(18)
  19. Dockerfile實(shí)戰(zhàn)(19)
  20. 容器的操作(20)
  21. Dockerfile實(shí)戰(zhàn)CMD和ENTRTYPOINT的配合(21)
  22. 容器的資源限制(22)
  23. docker網(wǎng)絡(luò)(23)
  24. docker學(xué)習(xí)必會(huì)網(wǎng)絡(luò)基礎(chǔ)(24)
  25. Linux網(wǎng)絡(luò)命名空間(25)
  26. Docker Bridge詳解(26)
  27. 容器之間的Link(27)
  28. 容器的端口映射(28)
  29. 容器網(wǎng)絡(luò)之host和none(29)
  30. 多容器復(fù)雜應(yīng)用的部署(30)
  31. overlay網(wǎng)絡(luò)和etcd實(shí)現(xiàn)多機(jī)的容器通信(31)
  32. docker的數(shù)據(jù)持久化存儲(chǔ)和數(shù)據(jù)共享(32)
  33. windows下vagrant 通過(guò)SecureCRT連接centos7(33)
  34. 數(shù)據(jù)持久化之Data Volume(34)
  35. 數(shù)據(jù)持久化之bind Mounting(35)
  36. docker 使用bind Mounting實(shí)戰(zhàn)(36)
  37. docker容器安裝wordpress(37)
  38. docker Compose到底是什么(38)
  39. Docker Compose的安裝和基本使用(39)
  40. Docker 水平擴(kuò)展和負(fù)載均衡(40)
    image
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容