续我的上篇博文:https://mp.csdn.net/postedit/89304557。即“构建docker镜像,并利用构建的镜像运行容器”的hello项目和docker项目已经构建好。
本篇博文是在上篇博文的基础上进行推进的,解决两个问题:
- webserver容器运行导致docker工程构建失败;
- 没有向registry私有仓库中推送构建好的镜像
一、实验环境(rhel7.3版本)
1、selinux和firewalld状态为disabled
2、各主机信息如下:
| 主机 | ip |
|---|---|
| server1(git) | 172.25.83.1 |
| server2(git,jdk,jenkins) | 172.25.83.2 |
二、基于Gitlab和Jenkins的自动化部署实例—构建docker镜像,推送构建好的docker镜像并利用构建的镜像运行容器
1、修改上篇博文配置好的hello项目中的配置
配置“构建”:勾掉之前选中的“Skip Push”。其配置图如下:
点击“高级”
点击“保存”
2、修改上篇博文配置好的docker项目中的配置
配置“构建”:在执行的shell命令中加一行命令用于判断
点击“保存”
3、在server1端test项目对应的目录下修改之前推送的index.html,并再次执行推送,来触发创建新的hello工程
[[email protected] test]# pwd
/root/test
[[email protected] test]# vim index.html
xin
is
a
good
girl
[[email protected] test]# git add index.html
[[email protected] test]# git commit -m "change index.html"
[[email protected] test]# git push -u origin master
4、测试:
<1>测试一:
点击“返回面板”,查看可以hello工程和docker是否已经配置好。s下面的球显示蓝色的,即表示构建成功
<2>测试二:
点击“hello”,进入hello工程的构建历史的主界面,点击“#6“左边”蓝色的球“,查看控制台输出,如果有输出,则表示hello工程已经配置好
点击“返回面板”——>“docker”,进入docker工程的构建历史的主界面,查看控制台输出,如果有输出,则表示可以docker工程已经配置好
<3>测试三:
在server2端查看对应的tag为6的镜像是否构建成功,查看webserver容器是否在运行,并访问webserver容器。如果镜像构建成功,容器在运行并且访问成功,则表示hello工程和docker工程已经配置好
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost:5000/nginx 6 62331e19c055 5 minutes ago 109MB
localhost:5000/nginx latest 62331e19c055 5 minutes ago 109MB
localhost:5000/nginx 5 94cbfc629e0a 39 minutes ago 109MB
nginx latest 344960c969db About an hour ago 109MB
nginx v1 5c0bec80cba3 4 hours ago 109MB
nginx <none> bb776ce48575 4 days ago 109MB
registry 2.3.1 83139345d017 3 years ago 166MB
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b84aee193efc localhost:5000/nginx "nginx -g 'daemon of…" 4 minutes ago Up 4 minutes 80/tcp webserver
010759261e68 registry:2.3.1 "/bin/registry /etc/…" 6 hours ago Up 6 hours 0.0.0.0:5000->5000/tcp registry
[[email protected] ~]# docker inspect webserver | grep IPAddress
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.3",
"IPAddress": "172.17.0.3",
[[email protected] ~]# curl 172.17.0.3
xin
is
a
good
girl
<4>测试四:
在server2端查看/opt/registry目录下是否有内容,如果有,则表示hello项目和docker项目配置成功
[[email protected] ~]# ls /opt/registry/
docker