原创文章,欢迎转载。转载请注明:转载自,谢谢!
原文链接地址:
今天部署一个复杂的application。源码地址:中的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.txtRUN pip install -r requirements.txt# Copy our code from the current folder to /app inside the containerADD . /app# 暴露端口80EXPOSE 80 # 启动容器命令CMD ["python", "app.py"]复制代码
Results App
暴露给外边访问的,实时的显示候选人的得票情况。是个node js项目。直接取PG数据库的结果。
Dockfile
FROM node:0.10RUN mkdir /appWORKDIR /appADD package.json /app/package.jsonRUN npm install && npm lsRUN mv /app/node_modules /node_modulesADD . /appENV PORT 80EXPOSE 80CMD ["node", "server.js"]复制代码
worker
读取redis效果,并将结果记录到PG数据库,是个java项目。
image.png
Dockfile
FROM java:7RUN apt-get update -qq && apt-get install -y maven && apt-get cleanWORKDIR /codeADD pom.xml /code/pom.xmlRUN ["mvn", "dependency:resolve"]RUN ["mvn", "verify"]# Adding source, compile and package into a fat jarADD src /code/srcRUN ["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-tiervolumes: db-data:networks: front-tier: back-tier:复制代码
docker-compose 一键部署
到docker-compose.yml目录
sudo service docker restartsudo docker-compose up#查看eth1的ip地址 映射了2个端口5000和5001ip 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.1Downloading: [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.1Downloading: [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.5Downloading: [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.1Downloading: [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.3Downloading: [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-5Downloading: [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.1Downloading: [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.0Downloading: [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: connectDownloading: [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覆盖原来的地址就可以解决了。