这是一篇关于如何实现Docker镜像的持续集成与持续交付的交付文档,产生这份文档的缘由是之前服务过的郑州市某家欠薪公司的及其客户一再打电话给我,希望我能提供一份相关操作文档。在我没有收到赔偿款和正式道歉视频之前,这份文档我不会披露更多细节,但可以在此大概描述一下关于Jenkins、Maven和Docker的部分。
什么是CI?CI全拼是Continuous Integration,译作持续集成,在业务语境中主要针对代码编写人员及测试人员,他们需要不定时地频繁提交代码、测试代码,以便快速发现软件工程中的代码质量问题并进行修复。这部分工作和平台运维没有任何关系,但和软件产品运维有较大关系。
什么是CD?CD全拼是Continuous Deployment或Continuous Delivery,根据协同分工的组织划分不同,CD有不同含义。在规模适当、权责明晰的产品型组织团队中,CD指代Continuous Deployment,意在将软件工程项目灵活部署到任意环境,主要供内部测试团队或尝鲜用户使用。而在规模较小而指责不清晰的管理型组织团队中,CD指代Continuous Delivery,意指将成熟的、定型的软件产品交付给终端使用者,涵盖了软件工程的部署和维保培训。在河南省的IT环境中,CD偏向于指代Continuous Delivery,有时也兼指Continuous Deployment和Continuous Delivery,比如我曾服务过的郑州市某ZY公司,总计职员27人,每个技术人员对应了5个管理人员,号称“人人皆可管理技术”。
该项目的工作流程描述:代码由《开发电脑》提交至《git》;触发《Jenkins》的自动代码编译并构建镜像,而后将镜像推送到《docker》仓库;《测试环境或生产环境》从《docker》仓库中拉取镜像进行《部署》。
项目实施环境:

Host OS:CentOS 7 1804 64Bit
 Package:git、JDK、Maven、Tomcat、Jenkins
 Role:Git/Registry、 Docker、Jenkins
 IP Range:192.168.207.177~192.168.207.180

(一)部署git服务

[googlebigtable0@localhost Downloads]$ su root
 Password:
 [root@localhost Downloads]# yum install -y git
 Loaded plugins: fastestmirror, langpacks
 Loading mirror speeds from cached hostfile• base: mirrors.aliyun.com
• extras: mirrors.aliyun.com
• updates: mirrors.aliyun.com
 Package git-1.8.3.1-23.el7_8.x86_64 already installed and latest version
 Nothing to do
 [root@localhost Downloads]# useradd git
 [root@localhost Downloads]# echo git | passwd --stdin git
 Changing password for user git.
 passwd: all authentication tokens updated successfully.
 [root@localhost Downloads]# su - git
 [git@localhost ~]$ mkdir PomanTeng.git
 [git@localhost ~]$ ls -F
 PomanTeng.git/
 [git@localhost ~]$ cd PomanTeng.git/
 [git@localhost PomanTeng.git]$ git --bare init
 Initialized empty Git repository in /home/git/PomanTeng.git/

(二)部署Docker服务

[googlebigtable1@localhost Downloads]$ su root
 Password:
 [root@localhost Downloads]# yum install -y yum-utils device-mapper-persistent-data lvm2
 Loaded plugins: fastestmirror, langpacks
 Loading mirror speeds from cached hostfile• base: mirrors.aliyun.com
• extras: mirrors.aliyun.com
• updates: mirrors.aliyun.com
 Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
 Package device-mapper-persistent-data-0.8.5-2.el7.x86_64 already installed and latest version
 Package 7:lvm2-2.02.186-7.el7_8.2.x86_64 already installed and latest version
 Nothing to do
 [root@localhost Downloads]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo Loaded plugins: fastestmirror, langpacks
 adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
 repo saved to /etc/yum.repos.d/docker-ce.repo
 [root@localhost Downloads]# yum install -y docker-ce
 Loaded plugins: fastestmirror, langpacks
 Loading mirror speeds from cached hostfile
 .........................................................................................................
 Installed:
 docker-ce.x86_64 3:19.03.12-3.el7Dependency Installed:
 container-selinux.noarch 2:2.119.2-1.911c772.el7_8 containerd.io.x86_64 0:1.2.13-3.2.el7 docker-ce-cli.x86_64 1:19.03.12-3.el7Complete!
 [root@localhost Downloads]#
 [root@localhost Downloads]# curl -sSL https:///daotools/set_mirror.sh | sh -s http://bc437cce.m.daocloud.io docker version >= 1.12
 {"registry-mirrors": ["http://bc437cce.m.daocloud.io"]}
 Success.
 You need to restart docker to take effect: sudo systemctl restart docker
 [root@localhost Downloads]# systemctl restart docker
 [root@localhost Downloads]# systemctl enable docker
 Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
 [root@localhost Downloads]# systemctl status docker
 ● docker.service - Docker Application Container Engine
 Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
 Active: active (running) since Wed 2020-08-12 13:56:30 EDT; 1min 23s ago
 Docs: https://docs.docker.com Main PID: 62339 (dockerd)
 CGroup: /system.slice/docker.service
 └─62339 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sockAug 12 13:56:29 localhost.localdomain dockerd[62339]: time="2020-08-12T13:56:29.641098974-04:00" level=info msg="scheme \"un...=grpc
 Aug 12 13:56:29 localhost.localdomain dockerd[62339]: time="2020-08-12T13:56:29.641109314-04:00" level=info msg="ccResolverW...=grpc
 Aug 12 13:56:29 localhost.localdomain dockerd[62339]: time="2020-08-12T13:56:29.641143808-04:00" level=info msg="ClientConn ...=grpc
 Aug 12 13:56:29 localhost.localdomain dockerd[62339]: time="2020-08-12T13:56:29.707335405-04:00" level=info msg="Loading con...art."
 Aug 12 13:56:29 localhost.localdomain dockerd[62339]: time="2020-08-12T13:56:29.980985856-04:00" level=info msg="Default bri...ress"
 Aug 12 13:56:30 localhost.localdomain dockerd[62339]: time="2020-08-12T13:56:30.270804237-04:00" level=info msg="Loading con...one."
 Aug 12 13:56:30 localhost.localdomain dockerd[62339]: time="2020-08-12T13:56:30.412313489-04:00" level=info msg="Docker daem...03.12
 Aug 12 13:56:30 localhost.localdomain dockerd[62339]: time="2020-08-12T13:56:30.412490651-04:00" level=info msg="Daemon has ...tion"
 Aug 12 13:56:30 localhost.localdomain dockerd[62339]: time="2020-08-12T13:56:30.430395667-04:00" level=info msg="API listen ...sock"
 Aug 12 13:56:30 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
 Hint: Some lines were ellipsized, use -l to show in full.
 [root@localhost Downloads]#

(三)部署Maven服务

[root@localhost Downloads]# tar -xzvf apache-maven-3.5.4-bin.tar.gz -C /usr/local/
 apache-maven-3.5.4/README.txt
 ...............................................................................................................................
 apache-maven-3.5.4/lib/jansi-1.17.1.jar
 [root@localhost Downloads]# mv /usr/local/apache-maven-3.5.4/ /usr/local/maven354
 [root@localhost Downloads]# tree -L 1 /usr/local/maven354/
 /usr/local/maven354/
 ├── bin
 ├── boot
 ├── conf
 ├── lib
 ├── LICENSE
 ├── NOTICE
 └── README.txt4 directories, 3 files
 [root@localhost Downloads]#
(四)部署Jenkins服务
[googlebigtable2@localhost Downloads]$ su root
 Password:
 [root@localhost Downloads]#
 [root@localhost Downloads]# tar -xzvf jdk-8u192-linux-x64.tar.gz -C /usr/local/
 jdk1.8.0_192/
 ......................................................................................................................
 jdk1.8.0_192/jre/Welcome.html
 jdk1.8.0_192/jre/README
 jdk1.8.0_192/README.html
 [root@localhost Downloads]# mv /usr/local/jdk1.8.0_192/ /usr/local/jdk180192
 [root@localhost Downloads]# tree -L 1 /usr/local/jdk180192/
 /usr/local/jdk180192/
 ├── bin
 ├── COPYRIGHT
 ├── include
 ├── javafx-src.zip
 ├── jre
 ├── lib
 ├── LICENSE
 ├── man
 ├── README.html
 ├── release
 ├── src.zip
 ├── THIRDPARTYLICENSEREADME-JAVAFX.txt
 └── THIRDPARTYLICENSEREADME.txt5 directories, 8 files
 [root@localhost Downloads]#
 (五)部署Tomcat服务
 [root@localhost Downloads]# tar -xzvf apache-tomcat-8.5.37.tar.gz -C /usr/local/
 apache-tomcat-8.5.37/conf/
 ................................................................................................................................
 apache-tomcat-8.5.37/bin/
 apache-tomcat-8.5.37/bin/
 apache-tomcat-8.5.37/bin/daemon.sh
 apache-tomcat-8.5.37/bin/
 apache-tomcat-8.5.37/bin/
 apache-tomcat-8.5.37/bin/shutdown.sh
 apache-tomcat-8.5.37/bin/startup.sh
 apache-tomcat-8.5.37/bin/
 apache-tomcat-8.5.37/bin/version.sh
 [root@localhost Downloads]# mv /usr/local/apache-tomcat-8.5.37/ /usr/local/tomcat8.5.37
 [root@localhost Downloads]# tree -L 1 /usr/local/tomcat8.5.37/
 /usr/local/tomcat8.5.37/
 ├── bin
 ├── BUILDING.txt
 ├── conf
 ├── CONTRIBUTING.md
 ├── lib
 ├── LICENSE
 ├── logs
 ├── NOTICE
 ├── README.md
 ├── RELEASE-NOTES
 ├── RUNNING.txt
 ├── temp
 ├── webapps
 └── work7 directories, 7 files
 [root@localhost Downloads]#
(六)部署Jenkins的Web服务
[root@localhost Downloads]# unzip jenkins.war -d /usr/local/tomcat8.5.37/webapps/ROOT
 Archive: jenkins.war
 .........................................................................................................................................
 inflating: /usr/local/tomcat8.5.37/webapps/ROOT/WEB-INF/lib/jenkins-core-2.235.4.jar
 [root@localhost Downloads]#
(七)安装和配置Jenkins管理项目
[root@localhost Downloads]# tail -f /usr/local/tomcat8.5.37/logs/catalina.out
 Please use the following password to proceed to installation:d21d68906c4945d7aea9eb1ad5c86359
This may also be found at: /root/.jenkins/secrets/initialAdminPassword

ctr save镜像 镜像cd_ctr save镜像