docker容器搭建jenkins并持久化数据
拉取最新镜像
# docker pull jenkins/jenkins:lts
系统下创建持久化数据目录
# mkdir /export/jenkins
临时启动容器,将jinkens的配置拷贝出来
# docker run -d -v jenkins_home:/var/jenkins_home -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
前往docker volumes路径(默认为/var/lib/docker/volumes)下将jenkins_home/_data下的所有文件拷贝至/export/jenkins下
# cp -r /export/docker/volumes/jenkins_home/_data/* /export/jenkins/
将文件属主改为1000,因为容器中jenkins用户id为1000
# chown -R 1000 /export/jenkins/
关闭并删除容器
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd09d0ae9f2b jenkins/jenkins:lts "/sbin/tini -- /us..." 25 minutes ago Up 25 minutes 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp modest_gates
# docker stop dd09d0ae9f2b
dd09d0ae9f2b
# docker rm dd09d0ae9f2b
dd09d0ae9f2b
挂载本地存储,启动容器
# docker run -d -v /export/jenkins:/var/jenkins_home -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
网页访问IP:8080,进行初始化配置
在容器/var/jenkins_home/secrets/initialAdminPassword文件中或在宿主机/export/jenkins/secrets/initialAdminPassword获取初始密码
选择安装默认插件,自动安装
默认官方镜像站可能无法访问,替换如下文件内容,可加快下载速度
http://mirror.xmission.com/jenkins/updates/update-center.json替换为https://mirrors.tuna.tsinghua.edu.cn/jenkins/
# cat hudson.model.UpdateCenter.xml
<?xml version='1.1' encoding='UTF-8'?>
<sites>
<site>
<id>default</id>
<url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/</url>
</site>
替换 updates/default.json中的http://updates.jenkins-ci.org/download/为https://mirrors.tuna.tsinghua.edu.cn/jenkins/
# sed -i 's/http\:\/\/updates.jenkins-ci.org\/download\//https\:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins\//g' default.json