Docker微服务-镜像构建交付和使用Rancher进行容器创建管理
先来架构,如图:
1.前端出口服务为阿里SLB
2.Zookeeper集群为整个微服务环境提供注册中心,Zookeeper集群每个znode的IP固定,也同样由config-service服务配置。
3.集中配置服务config-service,由git集中管理配置文件,config-service配置映射宿主机某个目录。配置如需修改直接Git中修改,触发宿主机映射的目录中进行git pull操作,然后重启对应的provider,配置即可生效。
4.facade作为分发器做分发服务。
微服务工作流程:
1)provider启动,读取写死的config-service配置服务,从配置服务中获取到Zookeeper地址,进行注册。
2)请求由阿里SLB分发至对应微服务facade,网关前往Zookeeper集群注册中心获取可用服务。
3)获取到可用provider后,facade进行分发请求,策略为轮询。
4)如后端provider挂了,无法提供服务,Zookeeper会自动剔除该服务的注册。
建立微服务基础运行环境,gateway网关、Zookeeper注册中心、config-service配置基础运行环境。开始构建以上基础运行环境:
一、创建zookeeper3.4.10集群服务
需包含了jdk和配置好环境变量的镜像,jdk1.8镜像。
jdk1.8镜像交付到阿里云Docker Registry仓库
Docker Rancher宿主机
1.下载jdk1.8.0_25.tar包,自行下载。
创建jdk构建build目录
mkdir -p /data/docker/ms-jdk ll -rw-r--r-- 1 root root 155 Dec 29 15:11 dockerfile drwxr-xr-x 9 root root 268 Nov 17 2017 jdk1.8.0_25
2.编写dockfile
cat dockerfile
FROM CentOS MAINTAINER jdk1.8 "[email protected]" ADD jdk1.8.0_25/ /usr/local/jdk1.8 ENV JAVA_HOME /usr/local/jdk1.8 ENV PATH $JAVA_HOME/bin:$PATH
3.构建
[root@rancher-qa ms-jdk]# docker build -t ms/jdk1.8:v1 . Sending build context to Docker daemon 308.6MB Step 1/5 : FROM centos latest: Pulling from library/centos a02a4930cb5d: Pull complete Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426 Status: Downloaded newer image for centos:latest ---> 1e1148e4cc2c Step 2/5 : MAINTAINER jdk1.8 "[email protected]" ---> Running in 74ba397d2ab5 ---> 57601effbcb9 Removing intermediate container 74ba397d2ab5 Step 3/5 : ADD jdk1.8.0_25/ /usr/local/jdk1.8 ---> e960522c0399 Removing intermediate container 9408672a94d9 Step 4/5 : ENV JAVA_HOME /usr/local/jdk1.8 ---> Running in 42d9c2b3239c ---> 9bb3badf22e0 Removing intermediate container 42d9c2b3239c Step 5/5 : ENV PATH $JAVA_HOME/bin:$PATH ---> Running in d8af2f726409 ---> 00d3c71ae0be Removing intermediate container d8af2f726409 Successfully built 00d3c71ae0be Successfully tagged ms/jdk1.8:v1
docker images 查看
4.登录阿里云容器镜像服务
创建镜像仓库名称ms-jdk1.8
5.镜像push到阿里云Docker Registry
切换到rancher/server
登录到阿里云Docker Registry
登录Docker Registry -> 打tag -> push到Docker Registry
[root@rancher-qa ms-jdk]# docker login [email protected] registry.cn-hangzhou.aliyuncs.com Password: ******** Login Succeeded [root@rancher-qa ms-jdk]# [root@rancher-qa ms-jdk]# docker tag 00d3c71ae0be registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/ms-jdk1.8:v1.0 [root@rancher-qa ms-jdk]# docker push registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/ms-jdk1.8:v1.0 The push refers to a repository [registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/ms-jdk1.8] 96f6833b8de8: Pushed 071d8bd76517: Pushed v1.0: digest: sha256:1c2f642e7e49cd607c36032612efcd875c191abc5edb642d7e86483d1d5b392d size: 742
查看:
至此,ms-jdk1.8镜像交付完成。
zookeeper3.4.10集群创建,并将Zookeeper3.4.10镜像交付到阿里云Docker Registry仓库。
1.zookeeper3.4.10集群构建前提准备:
zookeeper3.4.10集群需其配置文件中指定各个选举节点的ip和端口,并且zookeeper集群中的datadir(zoo.cfg配置中:dataDir=/tmp/zookeeper)中,需指定节点的myid,才能完成Zookeeper集群搭建。在不使用docker link功能前提下,容器化Zookeeper集群,需要解决:
1).myid问题。
2).Zookeeper集群节点(leader、follower)选举配置。
可使用docker内置的volume功能,将配置文件和Zookeeper的datadir映射至宿主机进行管理。
如在rancher中:
所以,宿主机必须存在:
1) zookeeper-config/,目录为Zookeeper所有配置文件,包含集群的选举节点IP和选举端口,主要zoo.cfg文件中。
ll zookeeper-config/ total 16 -rw-r--r-- 1 root root 535 Jan 4 17:43 configuration.xsl -rw-r--r-- 1 root root 2161 Jan 4 17:43 log4j.properties -rw-r--r-- 1 root root 1012 Jan 4 17:43 zoo.cfg -rw-r--r-- 1 root root 922 Jan 4 17:43 zoo_sample.cf
2) zookeeper-data01/,目录对应zookeeper集群中的datadir,有存放一个myid文件,Zookeeper集群启动后产生的数据也会持久化到此宿主机目录下。Zookeeper集群有3个znode节点,所以datadir有:
zookeeper-data02/
zookeeper-data03/
ll /data/docker/ drwxr-xr-x 3 root root 48 Jan 5 17:25 ms-zookeeper3.4.10 drwxr-xr-x 2 root root 92 Jan 5 16:54 zookeeper-config drwxr-xr-x 2 root root 18 Jan 4 17:59 zookeeper-data01 drwxr-xr-x 2 root root 18 Jan 4 18:02 zookeeper-data02 drwxr-xr-x 2 root root 18 Jan 4 18:02 zookeeper-data03
2.镜像构建
2.1 下载zookeeper-3.4.10.tar.gz包
wget https://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
创建zookeeper-3.4.10构建build目录
mkdir -p /data/docker/ms-zookeeper3.4.10/ -rw-r--r-- 1 root root 207 Jan 4 18:58 dockerfile drwxr-xr-x 10 root root 4096 Mar 23 2017 zookeeper-3.4.10
2.2 编写dockfile
vim /data/docker/ms-zookeeper3.4.10/dockerfile
FROM ms/jdk1.8:v1 MAINTAINER zookeeper3.4.10 "[email protected]" ADD zookeeper-3.4.10/ /usr/local/zookeeper/ WORKDIR /usr/local/zookeeper ENTRYPOINT ./bin/zkServer.sh start && tail -f zookeeper.out
其中zookeeper-3.4.10目录添加至镜像中,然后交付。但只是一个Zookeeper运行的模板,具体配置可通过volume,用宿主机的配置覆盖镜像中的配置。
2.3 构建,镜像
cd /data/docker/ms-zookeeper3.4.10 docker build -t ms/zookeeper3.4.10:v1 . docker images | grep zook ms/zookeeper3.4.10 v1 cb1bea8cf3d5 23 hours ago 567MB registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/tmp-zookeeper-ms v1 cb1bea8cf3d5 23 hours ago 567MB
镜像运行,本地docker本身命令行启动Zookeeper容器
[root@rancher-qa docker]# docker run --name zookeeper01 -it -v /data/docker/zookeeper-config/:/usr/local/zookeeper/conf/ -v /data/docker/zookeeper-data01/:/tmp/zookeeper/ ms/zookeeper3.4.10 /bin/bash
以上docker命令行启动卷映射目录正常,宿主机目录能映射到容器中。但rancher中用UI界面进行卷映射时,发现宿主机映射的目录在容器中并未映射到。待解决。
此问题是由于,rancher有两台主机,而容器都运行在未进行设置映射目录的宿主机中。此问题困扰近一周时间,<_>
2.4 登录阿里云容器镜像服务
创建镜像仓库名称tmp-zookeeper-ms
2.5 zookeeper镜像push到阿里云Docker Registry
切换到rancher/server
登录到阿里云Docker Registry
登录Docker Registry -> 打tag -> push到Docker Registry
[root@rancher-qa ms-zookeeper3.4.10]# docker login [email protected] registry.cn-hangzhou.aliyuncs.com Password: Login Succeeded [root@rancher-qa ms-zookeeper3.4.10]# [root@rancher-qa ms-zookeeper3.4.10]# docker tag cb1bea8cf3d5 registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/tmp-zookeeper-ms:v1 [root@rancher-qa ms-zookeeper3.4.10]# [root@rancher-qa ms-zookeeper3.4.10]# docker push registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/tmp-zookeeper-ms:v1 The push refers to a repository [registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/tmp-zookeeper-ms] ed1b06ecb437: Pushed 96f6833b8de8: Mounted from xmbaby-tmp/ms-jdk1.8 071d8bd76517: Mounted from xmbaby-tmp/ms-jdk1.8 v1: digest: sha256:c55b36fb410d7db9409e3ca4fb27e0d8d2d05e1970d99270ff9d5a6d8ee25e0b size: 954 [root@rancher-qa ms-zookeeper3.4.10]# docker images | grep zook registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/tmp-zookeeper-ms latest cb1bea8cf3d5 8 days ago 567MB registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/tmp-zookeeper-ms v1 cb1bea8cf3d5 8 days ago 567MB ms/zookeeper3.4.10 latest cb1bea8cf3d5 8 days ago 567MB ms/zookeeper3.4.10 v1 cb1bea8cf3d5 8 days ago 567MB
2.6查看
至此,tmp-zookeeper-ms镜像交付完成。
3.这里选择rancher来做docker集群的管理和编排,除了使用docker本身命令行界面启动Zookeeper容器外,推荐使用rancher UI界面进行容器管理和创建。
在rancher中,添加zk1、zk2、zk3容器服务:
创建zk1:
卷管理:
设置容器主机:
另两个znode节点,zk2、zk3同理操作,只是路径和名称做稍微改动。
进入Zookeeper容器中查看启动信息,查看Zookeeper机器znode2为集群leader:
二、创建config-service服务
集中配置服务config-service,作为公司微服务基础运行环境部分,需要优先单独创建。
为做好后期集中打包,使用maven工具,需先创建一maven镜像,该maven镜像集成了公司自己nexus服务,任何开发都可通过此镜像进行快速打包本地的开发环境的jar包。
Docker Rancher宿主机
1.下载apache-maven-3.3.9-bin.tar.gz包,自行下载。
创建maven构建build目录
mkdir -p /data/docker/maven3.3.9 ll drwxr-xr-x 6 root root 99 Jan 13 15:36 apache-maven-3.3.9 -rw-r--r-- 1 root root 8491533 Jan 13 15:34 apache-maven-3.3.9-bin.tar.gz -rw-r--r-- 1 root root 393 Jan 13 16:53 dockerfile drwxr-xr-x 9 root root 268 Jan 13 15:43 jdk1.8.0_25 -rwxr-xr-x 1 root root 55 Jan 13 16:53 maven.sh
2.编写dockfile
cat dockerfile
FROM ms/jdk1.8:v1 MAINTAINER maven-3.3.9 "[email protected]" RUN mkdir /usr/local/maven-3.3.9/ #&& mkdir /usr/local/jdk1.8/ #因基于ms/jdk1.8:v1镜像,已有的jdk环境 ADD apache-maven-3.3.9/ /usr/local/maven-3.3.9/ #ADD jdk1.8.0_25/ /usr/local/jdk1.8/ ADD maven.sh /tmp/ ENV JAVA_HOME /usr/local/jdk1.8 ENV M2_HOME /usr/local/maven-3.3.9 ENV PATH $JAVA_HOME/bin:$M2_HOME/bin:$PATH CMD /tmp/maven.sh
cat maven.sh
#!/bin/bash cd /data/httpd/${msname} mvn clean install
3.构建
[root@rancher-qa maven3.3.9]# docker build -t ms/maven-3.3.9 . Sending build context to Docker daemon 327.2MB Step 1/9 : FROM ms/jdk1.8:v1 ---> 00d3c71ae0be Step 2/9 : MAINTAINER maven-3.3.9 "[email protected]" ---> Using cache ---> 80a6d05eae5a Step 3/9 : RUN mkdir /usr/local/maven-3.3.9/ #&& mkdir /usr/local/jdk1.8/ ---> Using cache ---> 92ac17c859a8 Step 4/9 : ADD apache-maven-3.3.9/ /usr/local/maven-3.3.9/ ---> Using cache ---> fa81af79d732 Step 5/9 : ADD maven.sh /tmp/ ---> Using cache ---> 034053775e26 Step 6/9 : ENV JAVA_HOME /usr/local/jdk1.8 ---> Using cache ---> ad8e78b5a021 Step 7/9 : ENV M2_HOME /usr/local/maven-3.3.9 ---> Running in cfae5d0a6e53 ---> ccfcc8638e43 Removing intermediate container cfae5d0a6e53 Step 8/9 : ENV PATH $JAVA_HOME/bin:$M2_HOME/bin:$PATH ---> Running in 30b2f568c1a3 ---> 27e68ef34a42 Removing intermediate container 30b2f568c1a3 Step 9/9 : CMD /tmp/maven.sh ---> Running in db48895f5502 ---> 21c6f1a3b0cf Removing intermediate container db48895f5502 Successfully built 21c6f1a3b0cf Successfully tagged ms/maven-3.3.9:latest [root@rancher-qa maven3.3.9]# [root@rancher-qa maven3.3.9]# docker images | grep maven ms/maven-3.3.9 latest 21c6f1a3b0cf 34 minutes ago 519MB
运行此maven镜像,打包命令示例:
[root@rancher-qa maven3.3.9]# docker run --rm -it -v /data/docker/ms-config/:/data/httpd/config-service/ -e msname=config-service ms/maven-3.3.9
说明:-v宿主机配置目录/data/docker/ms-config/映射到容器/data/httpd/config-service/,-e定义maven.sh脚本${msname}变量。
4.登录阿里云容器镜像服务
创建本地仓库名称ms-maven-3.3.9
5.镜像push到阿里云Docker Registry
切换到rancher/server
登录到阿里云Docker Registry
登录Docker Registry -> 打tag -> push到Docker Registry
[root@rancher-qa ms-jdk]# docker login [email protected] registry.cn-hangzhou.aliyuncs.com Password: ********** Login Succeeded [root@rancher-qa ms-jdk]# [root@rancher-qa ms-jdk]# docker tag 21c6f1a3b0cf registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/ms-maven-3.3.9:latest [root@rancher-qa ms-jdk]# docker push registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/ms-maven-3.3.9:latest The push refers to a repository [registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/ms-maven-3.3.9] 607c588ba0d1: Pushed 2e4a77c00b58: Pushed 48c8f5464987: Pushed 96f6833b8de8: Mounted from xmbaby-tmp/tmp-zookeeper-ms 071d8bd76517: Mounted from xmbaby-tmp/tmp-zookeeper-ms latest: digest: sha256:9ceac47cffbf0c35ed66212a042ad10f3905cae924033caf4cbca8cbf4dbf4dd size: 1367
查看:
至此,ms-maven-3.3.9镜像交付完成。此镜像交付完成后,后期基本无需改动,直接latest版本。
服务config-service镜像开始交付:
1.1准备集中配置项目alaxiaoyou-config-service-0.0.1-SNAPSHOT.jar包,gitlab仓库中。
创建config-service构建build目录
mkdir -p /data/httpd/ms-config-service-tmp -rw-r--r-- 1 root root 276 Jan 14 17:34 dockerfile drwxr-xr-x 2 root root 58 Jan 14 17:31 target
1.2 编写dockfile
cat /data/httpd/ms-config-service-tmp/dockerfile
FROM ms/jdk1.8:v1 MAINTAINER tmp-config-service "[email protected]" RUN mkdir -p /data/httpd/ ADD target/alaxiaoyou-config-service-0.0.1-SNAPSHOT.jar /data/httpd/ WORKDIR /data/httpd/ ENTRYPOINT java -Xmx128m -Xss512k -jar alaxiaoyou-config-service-0.0.1-SNAPSHOT.jar
说明:ENTRYPOINT进入容器中执行此jar包。
1.3 构建,镜像
docker build -t ms/config-service . Sending build context to Docker daemon 21.2MB Step 1/6 : FROM ms/jdk1.8:v1 ---> 00d3c71ae0be Step 2/6 : MAINTAINER tmp-config-service "[email protected]" ---> Running in a3e0038610ff ---> 75d7642e16ec Removing intermediate container a3e0038610ff Step 3/6 : RUN mkdir -p /data/httpd/ ---> Running in 4b1ff33f58df ---> f43b916f6835 Removing intermediate container 4b1ff33f58df Step 4/6 : ADD target/alaxiaoyou-config-service-0.0.1-SNAPSHOT.jar /data/httpd/ ---> 99608e52e219 Removing intermediate container 0bd4d9130dd0 Step 5/6 : WORKDIR /data/httpd/ ---> 656a442c7ac2 Removing intermediate container d18fbdc1c6a6 Step 6/6 : ENTRYPOINT java -Xmx128m -Xss512k -jar alaxiaoyou-config-service-0.0.1-SNAPSHOT.jar ---> Running in 0371f9addb5d ---> c7375c40286e Removing intermediate container 0371f9addb5d Successfully built c7375c40286e Successfully tagged ms/config-service:latest [root@rancher-qa ms-config-service-tmp]# pwd /data/httpd/ms-config-service-tmp [root@rancher-qa ms-config-service-tmp]# docker images | grep config ms/config-service latest c7375c40286e 2 minutes ago 530MB registry.cn-hangzhou.aliyuncs.com/xmbaby-pre/ms-config latest 51a4521d7581 24 months ago 578MB
1.4 登录阿里云容器镜像服务
创建镜像本地仓库名称tmp-config-service-ms
1.5 镜像push到阿里云Docker Registry
切换到rancher/server
登录到阿里云Docker Registry
登录Docker Registry -> 打tag -> push到Docker Registry
[root@rancher-qa ms-config-service-tmp]# docker login [email protected] registry.cn-hangzhou.aliyuncs.com Password: ****** Login Succeeded [root@rancher-qa ms-config-service-tmp]# docker tag c7375c40286e registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/tmp-config-service-ms:latest [root@rancher-qa ms-config-service-tmp]# [root@rancher-qa ms-config-service-tmp]# docker push registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/tmp-config-service-ms:latest The push refers to a repository [registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/tmp-config-service-ms] 76925e259a39: Pushed d31d3604ba1d: Pushed 96f6833b8de8: Mounted from xmbaby-tmp/ms-maven-3.3.9 071d8bd76517: Mounted from xmbaby-tmp/ms-maven-3.3.9 latest: digest: sha256:78c0489e045a1a9a7220ea941ca8b7fd6db348e5423e478a45ac2bbc2117c180 size: 1161
至此,tmp-config-service-ms镜像交付完成。
- tmp-config-service-ms镜像启动,统一用rancher编排UI工具来启动。
tmp-config-service-ms服务启动需依赖宿主机的目录,这个目录,是本地git仓库项目,gitlab中为:[email protected]。provider配置修改,都通过gitlab进行修改,会进行更新到本地目录中,重启此provider即可生效。
2.1 启动tmp-config-service-ms服务,rancher中操作。
创建服务tmp-config-service-ms:
设置卷:
设置容器主机名:
2.2 启动tmp-config-service-ms容器服务。此provider只在启动初,会找一次config-service,但此config-service服务为单点服务。不过,容器可快速销毁和生成的特性,即使此config-service配置服务出现问题,也可立即自动重启或手工销毁有问题的容器,并重新生成新的config-service服务容器,此过程为秒级,是可接受配置服务为单点。
进入config-service服务容器,查看启动情况,日志查看:
三、创建gateway-service服务
网关gateway-service服务是整个微服务架构的入口,在构建provider前,必须建立先创建好网关服务。
git clone网关项目代码,[email protected]
1.创建网关项目目录:
mkdir -p /data/httpd/ms-api-gateway-tmp/alaxiaoyou-api-gateway
[root@rancher-qa ms-api-gateway-tmp]# git clone [email protected] Cloning into 'alaxiaoyou-api-gateway'... remote: Counting objects: 1198, done. remote: Compressing objects: 100% (552/552), done. remote: Total 1198 (delta 423), reused 554 (delta 241) Receiving objects: 100% (1198/1198), 108.00 KiB | 0 bytes/s, done. Resolving deltas: 100% (423/423), done. [root@rancher-qa ms-api-gateway-tmp]# [root@rancher-qa ms-api-gateway-tmp]# ll total 0 drwxr-xr-x 4 root root 44 Jan 14 19:10 alaxiaoyou-api-gateway [root@rancher-qa ms-api-gateway-tmp]# pwd /data/httpd/ms-api-gateway-tmp [root@rancher-qa ms-api-gateway-tmp]# cd alaxiaoyou-api-gateway/ [root@rancher-qa alaxiaoyou-api-gateway]# [root@rancher-qa alaxiaoyou-api-gateway]# ll total 8 -rw-r--r-- 1 root root 4811 Jan 14 19:10 pom.xml drwxr-xr-x 3 root root 18 Jan 14 19:10 src [root@rancher-qa alaxiaoyou-api-gateway]# [root@rancher-qa alaxiaoyou-api-gateway]# pwd /data/httpd/ms-api-gateway-tmp/alaxiaoyou-api-gateway
在gateway-service项目目录下,运行网关代码打包命令:
docker run --rm -it -v /data/httpd/ms-api-gateway-tmp/alaxiaoyou-api-gateway:/data/httpd/gateway-service/ -e msname=gateway-service ms/maven-3.3.9 [root@rancher-qa alaxiaoyou-api-gateway]# docker run --rm -it -v /data/httpd/ms-api-gateway-tmp/alaxiaoyou-api-gateway:/data/httpd/gateway-service/ -e msname=gateway-service ms/maven-3.3.9 [root@rancher-qa alaxiaoyou-api-gateway]# ll total 58436 -rw-r--r-- 1 root root 59823092 Jan 14 19:27 alaxiaoyou-api-gateway-0.0.1-SNAPSHOT.jar -rw-r--r-- 1 root root 343 Jan 14 19:28 dockerfile drwxr-xr-x 3 root root 20 Jan 14 19:28 gateway-service -rw-r--r-- 1 root root 4811 Jan 14 19:10 pom.xml drwxr-xr-x 3 root root 18 Jan 14 19:10 src
此打包命令,目前并未成功将包alaxiaoyou-api-gateway-0.0.1-SNAPSHOT.jar打出,该包从其他机器cp过来。待解决。
2.创建网关项目dockerfile
vim /data/httpd/ms-api-gateway-tmp/alaxiaoyou-api-gateway/dockerfile
FROM ms/jdk1.8:v1 MAINTAINER gateway-service "[email protected]" RUN mkdir /data/httpd/ -p ADD gateway-service/target/alaxiaoyou-api-gateway-0.0.1-SNAPSHOT.jar /data/httpd/ EXPOSE 80 #此处虽然开启了80端口映射,但是并没有做link链接 WORKDIR /data/httpd/ ENTRYPOINT java -jar alaxiaoyou-api-gateway-0.0.1-SNAPSHOT.jar
说明:ENTRYPOINT进入容器中执行此jar包。
3.构建,镜像
[root@rancher-qa alaxiaoyou-api-gateway]# docker build -t ms/tmp-gateway-service . Sending build context to Docker daemon 60.27MB Step 1/7 : FROM ms/jdk1.8:v1 ---> 00d3c71ae0be Step 2/7 : MAINTAINER gateway-service "[email protected]" ---> Using cache ---> bf3f97f0bda2 Step 3/7 : RUN mkdir -p /data/httpd/ ---> Running in da244cb64552 ---> 743c35c3c4d8 Removing intermediate container da244cb64552 Step 4/7 : ADD gateway-service/target/alaxiaoyou-api-gateway-0.0.1-SNAPSHOT.jar /data/httpd/ ---> 9e45fe4b20a4 Removing intermediate container 8e3022556068 Step 5/7 : EXPOSE 80 ---> Running in e4dbaaa58778 ---> 299398d4af46 Removing intermediate container e4dbaaa58778 Step 6/7 : WORKDIR /data/httpd/ ---> 2e6bc4bdf39d Removing intermediate container 8428111522be Step 7/7 : ENTRYPOINT java -jar alaxiaoyou-api-gateway-0.0.1-SNAPSHOT.jar ---> Running in 8ce9968b7bef ---> c2f59d36052d Removing intermediate container 8ce9968b7bef Successfully built c2f59d36052d Successfully tagged ms/tmp-gateway-service:latest [root@rancher-qa alaxiaoyou-api-gateway]# [root@rancher-qa alaxiaoyou-api-gateway]# docker images|grep gate ms/tmp-gateway-service latest c2f59d36052d 16 seconds ago 569MB registry.cn-hangzhou.aliyuncs.com/xmbaby-test/test-gateway-ms latest d86bef9f01e9 14 months ago 617MB
4.登录阿里云容器镜像服务
创建本地仓库名称:tmp-gateway-service-ms
5.镜像push到阿里云Docker Registry
切换到rancher/server
登录到阿里云Docker Registry
登录Docker Registry -> 打tag -> push到Docker Registry
[root@rancher-qa alaxiaoyou-api-gateway]# docker login [email protected] registry.cn-hangzhou.aliyuncs.com Password: Login Succeeded [root@rancher-qa alaxiaoyou-api-gateway]# docker tag c2f59d36052d registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/tmp-gateway-service-ms [root@rancher-qa alaxiaoyou-api-gateway]# [root@rancher-qa alaxiaoyou-api-gateway]# docker push registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/tmp-gateway-service-ms The push refers to a repository [registry.cn-hangzhou.aliyuncs.com/xmbaby-tmp/tmp-gateway-service-ms] 29ffcfda7ded: Pushed 202759902df6: Pushed 96f6833b8de8: Mounted from xmbaby-tmp/tmp-config-service-ms 071d8bd76517: Mounted from xmbaby-tmp/tmp-config-service-ms latest: digest: sha256:825a0ec026c1f7c6eea01c2e5236c42dba11209b17ccd2ffad2b314c99b58b2d size: 1161
6.镜像查看:
至此,gateway-service-ms镜像交付完成。
用rancher编排UI工具来���动gateway-service:
1.进入rancher应用栈添加服务。因为网关gateway服务需映射80端口至宿主机,因此,创建容器选择“总是在每台主机上运行一个此容器的实例”。映射80端口。添加关联的目标服务。
网关服务gateway-service启动会连接关联的目标服务config-service,config-service是通过git管理的config配置项目来获取配置信息给网关服务。关联Zookeeper集群注册服务。
2.自动重启选择“从不(仅启动一次)”:
3.对于网关服务,可使用docker本身来管理内存分配,可进行动态调整:
4.进入容器查看gateway-service服务启动。
自此,网关服务gateway-service添加完成。