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

设置容器主机名:

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

2.2 启动tmp-config-service-ms容器服务。此provider只在启动初,会找一次config-service,但此config-service服务为单点服务。不过,容器可快速销毁和生成的特性,即使此config-service配置服务出现问题,也可立即自动重启或手工销毁有问题的容器,并重新生成新的config-service服务容器,此过程为秒级,是可接受配置服务为单点。
进入config-service服务容器,查看启动情况,日志查看:

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

三、创建gateway-service服务

网关gateway-service服务是整个微服务架构的入口,在构建provider前,必须建立先创建好网关服务。
git clone网关项目代码,git@xxxx.git

1.创建网关项目目录:
mkdir -p /data/httpd/ms-api-gateway-tmp/alaxiaoyou-api-gateway

[root@rancher-qa ms-api-gateway-tmp]# git clone git@xxxxx.git 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 "name@alaxiaoyou.com" 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 "yuhuanghui@alaxiaoyou.com" ---> 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

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

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