您现在的位置是:首页 > 博文答疑 > Docker 搭建 Jenkins 博文答疑
Docker 搭建 Jenkins
Leo2022-10-21【10】
简介Docker Jenkins
环境准备:
操作系统:CentOS Linux release 7.x
Docker 版本:20.10.17
Jenkins 版本:2.319.1
Docker下载Jenkins
docker pull jenkins/jenkins:lts //最新版
[root@site1 /]# docker pull jenkins/jenkins:lts
lts: Pulling from jenkins/jenkins
647acf3d48c2: Pull complete
832e288237bc: Pull complete
ea194d1bd1da: Pull complete
98569593b9fd: Pull complete
dfe249e8cdf2: Pull complete
0f6f2e6d37bb: Pull complete
07fcb98649b6: Pull complete
1e33c26b1882: Pull complete
7b24f0e29fe1: Pull complete
4d90ef3a8f3b: Pull complete
d98c8e675bea: Pull complete
b45fc2bf9fd7: Pull complete
d6e1fda9effc: Pull complete
3635a44047f2: Pull complete
486e1776d3bc: Pull complete
41233d151800: Pull complete
14a67803c2b3: Pull complete
Digest: sha256:c1d02293a08ba69483992f541935f7639fb10c6c322785bdabaf7fa94cd5e732
Status: Downloaded newer image for jenkins/jenkins:lts
docker.io/jenkins/jenkins:lts
查看Jenkins镜像
docker images
docker inspect jenkins镜像ID
[root@site1 /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
demo 1.0 e35809570974 2 months ago 672MB
redis latest 7614ae9453d1 10 months ago 113MB
mongo latest dfda7a2cf273 10 months ago 693MB
jenkins/jenkins lts 2a4bbe50c40b 10 months ago 441MB
创建一个Jenkins目录
mkdir /data/jenkins_home;
[root@site1 /]# mkdir data
[root@site1 /]# mkdir /data/jenkins_home
安装启动Jenkins容器
docker run -d --name jenkins -p 8081:8080 -v /data/jenkins_home:/var/jenkins_home jenkins/jenkins:lts;
备注:
-d //启动在后台
--name //容器名字
-p //端口映射(8081:宿主主机端口,8080:容器内部端口)
-v //数据卷挂载映射(/data/jenkins_home:宿主主机目录,另外一个即是容器目录)
enkins/jenkins:lts //Jenkins镜像(最新版)
-v /var/run/docker.sock:/var/run/docker.sock \ #如果需要在jenkins容器像宿主机一样操作其他容器,可以加上这个
查看Jenkins启动情况
[root@site1 /]# docker ps | grep jenkins
[root@site1 /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c0990814399 jenkins/jenkins:lts "/sbin/tini -- /usr/…" About a minute ago Exited (1) About a minute ago jenkins
afb60aeda908 mongo "docker-entrypoint.s…" 4 weeks ago Up 16 minutes 0.0.0.0:27017->27017/tcp, :::27017->27017/tcp mongo-nops
安装过程遇到的小问题
启动失败,查看log,显示没有权限,
因为/data/jenkins_home 目录是root权限
[root@site1 /]# docker logs jenkins
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
解决:
chown -R 1000:1000 /data/jenkins_home //用户组改变
[root@site1 /]# chown -R 1000:1000 /data/jenkins_home
[root@site1 /]# docker start jenkins
jenkins
[root@site1 /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c0990814399 jenkins/jenkins:lts "/sbin/tini -- /usr/…" 3 minutes ago Up 4 seconds 50000/tcp, 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp jenkins
访问Jenkins:
管理配置Jenkins
在安装完成后,默认生成了一个登录密码,首次登录需要这个密码。
密码路径:var/jenkins_home/secrets/initialAdminPassword //容器内部
查找密码:
docker exec -it jenkins_01 bash //进入jenkins容器
cat /var/jenkins_home/secrets/initialAdminPassword //查看密码
得到密码后,在网页上输入:
安装插件
新手安装建议选择:Install suggested plugins,然后会自动安装。
管理用户创建
这个用户就是最大管理者权限,相当于admin
Jenkins配置完成
配置完管理员用户后,一直下一步便可以完成配置进入Jenkins