原创文章,欢迎转载。转载请注明:转载自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项目。
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覆盖原来的地址就可以解决了。
往期精彩
- docker导学(一)
- 容器的技术概述(二)
- docker的魅力初体验-5分钟安装wordpress不走弯路(三)
- docker官网介绍(四)
- 如何在mac上安装docker(五)
- 如何在window上安装docker(六)
- 如何在mac上通过vagrant安装虚拟机(七)
- 如何在window上通过vagrant安装虚拟机(八)
- docker-Machine的本地使用(九)
- docker-Machine的本地使用(十)
- 在linux/mac下通过Docker-Machine在阿里云上的使用(11)
- docker架构和底层技术(12)
- docker Image概述(13)
- 手动建立一个base Image(14)
- 什么是Container(15)
- 构建自己的Docker镜像(16)
- Dockerfile详解(17)
- 镜像的发布(18)
- Dockerfile实战(19)
- 容器的操作(20)
- Dockerfile实战CMD和ENTRTYPOINT的配合(21)
- 容器的资源限制(22)
- docker网络(23)
- docker学习必会网络基础(24)
- Linux网络命名空间(25)
- Docker Bridge详解(26)
- 容器之间的Link(27)
- 容器的端口映射(28)
- 容器网络之host和none(29)
- 多容器复杂应用的部署(30)
- overlay网络和etcd实现多机的容器通信(31)
- docker的数据持久化存储和数据共享(32)
- windows下vagrant 通过SecureCRT连接centos7(33)
- 数据持久化之Data Volume(34)
- 数据持久化之bind Mounting(35)
- docker 使用bind Mounting实战(36)
- docker容器安装wordpress(37)
- docker Compose到底是什么(38)
- Docker Compose的安装和基本使用(39)
- Docker 水平扩展和负载均衡(40)