Centos7- Docker方式安装Jenkins

拉取镜像

1
pull jenkins/jenkins

拉取成功后查看镜像

1
2
3
4
[root@iZ2ze1autlxng10rm79oi0Z ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/jenkins/jenkins latest 482543872bd9 4 days ago 441 MB

新建数据卷映射目录并赋予权限

1
2
3
4
5
6
[root@iZ2ze1autlxng10rm79oi0Z ~]# mkdir /jenkins_home
[root@iZ2ze1autlxng10rm79oi0Z ~]# cd /
[root@iZ2ze1autlxng10rm79oi0Z /]# ls
bin boot data dev etc home jenkins_home lib lib64 lost+found media mnt opt patch proc root run sbin srv sys tmp usr var www
[root@iZ2ze1autlxng10rm79oi0Z /]# chmod 777 -R /jenkins_home/

启动容器并查看容器是否启动成功

1
2
3
4
5
6
7
[root@iZ2ze1autlxng10rm79oi0Z /]# docker run -d --name jenkins -p 8080:8080 -v  /jenkins_home:/var/jenkins_home  jenkins/jenkins:latest
165315ab2babf7264ac5dd87a6f791582d1b0ae995e0aa62c69aa6a5a128f25c

[root@iZ2ze1autlxng10rm79oi0Z /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
165315ab2bab jenkins/jenkins:latest "/sbin/tini -- /us..." 8 seconds ago Up 7 seconds 0.0.0.0:8080->8080/tcp, 50000/tcp jenkins

说明:

  • -d //启动在后台
  • --name //容器名字
  • -p //端口映射(8080:宿主主机端口,8080:容器内部端口)
  • -v //数据卷挂载映射(/jenkinshome:宿主主机目录,另外一个即是容器目录)

访问jenkins

  1. 访问jenkins获取密码打开浏览器访问对应Ip:8080端口,注意服务器上开放8080端口,访问成功后会验证获取管理员密码。
1
2
3
#开放8080端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload # 配置立即生效

进入容器查看密码

1
2
3
4
[root@iZ2ze1autlxng10rm79oi0Z /]# docker exec -it jenkins /bin/bash
jenkins@165315ab2bab:/$ cat /var/jenkins_home/secrets/initialAdminPassword
13e98006aa3a40ae9b13c8315e1fa0ee

参考资料

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/119911722