Docker + Rancher build the deployment pipeline

For many years, in terms of the deployment of the project,

1: rz before using ftp or upload updated count each update package , change the directory , update missing , backup , error reduction , start the work had to be out on a hour or even longer, if more than two servers that heart It is cold;

2: Useful svn or git later, the pull on the server is compiled or directory packet;

3: After now and then to implement an automated build deployments with jenkins, jenkins configured pipeline, after each subsequent submission of the code requires only the click of a button;

 

Mode 3 personal feeling is very good, very convenient, as well as jenkins + docker way and so on, do not make comparison, recording deployment currently in use: Dockerfile

Process Introduction

1, ready alpine mirror, made with jdk, mvn environment and project lib package, mvn dependent on local warehouse, the system plug-ins, create the base image

2, Ali cloud container mirror service, upload base image, set construction rules

3, item code added Dockerfile, logic to copy the source code generated by the base image container, run mvn compiler package, the package started to move the item to the desired path, can be used here to build a multi-stage reducing the volume of the mirror, and finally the container is provided to start the script

 

Ready to work

// install Docker 
yum -y install docker- IO 

// Start 
Service Docker Start 

// set the boot 
chkconfig docker on

{
"registry-mirrors": [""]
}

Log Ali cloud container mirror service -> Mirror accelerator -> accelerator Address

File address /etc/docker/daemon.json

You can restart the service

 

First talk about the benefits of docker deployment project:

1, isolation , security (no need to worry about outside influences on the container system, of course, there are special circumstances, we will discuss later)
  then the advantage is reflected in where isolation of the actual project it?

  : In a distributed environment, the server may present a plurality of the same service (the same port), or a plurality of different service environments (such jdk7, jdk8, php, python, etc.) are present in the same server, so that isolation and without conflicts between them!

  : Because isolation, so the collapse of a single container will not affect the operation of other services, each container can assign the appropriate system resources (including CPU, memory and disk space)

2, portability

  windows, linux can run other environments have not used not list

3, version control and continuous integration

  Combined with other plug-ins, you can easily do a whole project deployment process, including the compilation, packaging, release updates, rollback, and so

4, low cost

  Because of these benefits as well as formal docker advantage in resource allocation, docker using low-cost, effective

 

Then use the docker to consider in advance or pay attention to those things that those aspects of it:

1, mirroring the size of the problem: springboot like running such a project needs to be based linux or windows system jdk environment, then the base image size is a big problem

linux system we use alpine, with jdk environment I use dockerhub above Deal  https://hub.docker.com/r/anapsix/alpine-java  , can also deal with their own image processing according to the official website

2, compiled packaged Question: I installed maven directly to the system in the production of mirror, use mvn compile package

3, the last question is the most critical management tools: excellent management tools can reduce 90 percent of our workload, I use Rancher, default comes with cattle, of course, there are other scheduling tools can be used k8s

 

Here are two management tools Portainer and Rancher, small stand-alone project or test you can try the former, I use the production environment Rancher

Docker interface management Portainer (I am here on a Win10 operating system)

docker pull portainer/portainer

//启动
docker run -d -p 9000:9000 --restart=always --name prtainer-test portainer/portainer

 

Note: On win10 installation docker in a virtual machine environment, you need to choose a way to connect remote, first open the 2375 port

Enter the command test

Test-NetConnection -ComputerName localhost -Port 2375

Testing by

Browser access http://127.0.0.1:9000

After creating a user, select the remote environment, fill in the URL of Endpoint  docker.for.win.localhost: 2375 ,

 

 It is shown below normal

 对容器或镜像的操注意别把portainer相关的删了

 

 由于我在使用自建带密码的Registries时无法通过验证,只能放弃Portainer,Shipyard网上评价比较高,但是停止维护了,在作者的github的首页有推荐Rancher、dockerui和Portainer

那下面我就切换到Rancher

docker pull rancher/server 

docker run -d --restart=always -p 8089:8080 rancher/server

 容器已启动,大概要等几十秒才能访问http://localhost:8089

第一步配置用户

然后改一下主机注册地址,不要用localhost或者127.0.0.1 改成内网ip,保存

 

接着添加主机

 

第4步 我填的是内网IP,目前生产环境用宿主机内网IP一切正常, (或许用公网IP能有其他用处,比如跨外网的容器连接,我还没试)

第5步按提示操作即可,

 

从阿里云拉取镜像,首先在镜像库配置账号信息,然后新建容器,注意“选择镜像”填的是阿里云镜像服务中“公网地址:镜像版本号”,如果是同地域的可以用专用网络或者经典网络地址

大项目用Rancher,功能非常强大,服务编排、升级、回滚、扩容、调度,如同神器

 附上文档地址:https://rancher.com/docs/rancher/v1.6/zh/

 

 

我遇到需要注意的问题

1、如果Dockerfile中RUN mvn编译项目出现以下错误:

unmappable character (0xE4) for encoding US-ASCII 

解决办法:

在Dockerfile中加上

ENV LANG en_US.utf8

 

 2、Dockerfile 做的镜像带CMD启动脚本的情况   一启动就关闭

CMD执行脚本 本质上是用了 /bin/sh -c,因为这是容器的主进程,所以当脚本执行完之后容器就会退出。那么可以在脚本的最后加上tail -f /dev/null

 

3、Alpine安装配置jdk无法成功

网友表示Alpine缺少glibc,我没有去深入研究,而是直接用dockerhub上面已经处理好的镜像

 

4、镜像体积优化

使用多阶段构建方法

 

5、注意看Rancher的文档

比如网络模式注意要选择“托管” 才能使用到大部分的功能,标签的合理使用,负载均衡的扩展数量限制问题,默认网段10.42.0.0/16 等等

 

6、容器之间通信失败

可能是安全组的问题,配置1/65535 IPv4地址段访问 10.42.0.0/16 ,没有确认是否有影响,失败的时候可以尝试一下该方法

 

7、这是一个神坑,当防火墙改动后,容器与容器之间、宿主机与容器之间无法通信,不知道是Rancher的问题还是docker的问题

解决办法:重启docker服务

 

8、第二坑,确认中

 

 

 转载请注明博客出处:http://www.cnblogs.com/cjh-notes/

 

Guess you like

Origin www.cnblogs.com/cjh-notes/p/11295925.html