镜像构建交付和使用Rancher进行容器创建管理(4)

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 "name@alaxiaoyou.com" 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 "yuhuanghui@alaxiaoyou.com" ---> 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

Docker微服务-镜像构建交付和使用rancher进行容器创建管理

1.5 镜像push到阿里云Docker Registry
切换到rancher/server
登录到阿里云Docker Registry
登录Docker Registry -> 打tag -> push到Docker Registry

[root@rancher-qa ms-config-service-tmp]# docker login --username=name@alaxiaoyou.com 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中为:git@xxxx.git。provider配置修改,都通过gitlab进行修改,会进行更新到本地目录中,重启此provider即可生效。

2.1 启动tmp-config-service-ms服务,rancher中操作。
创建服务tmp-config-service-ms:

Docker微服务-镜像构建交付和使用rancher进行容器创建管理

设置卷:

Docker微服务-镜像构建交付和使用rancher进行容器创建管理

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/76c900b84e720f5a30e284909548b750.html