Jenkins Docker镜像
git clone https://github.com/fifilyu/docker-jenkins.git
cd docker-jenkins
docker buildx build -t fifilyu/jenkins:latest .
- sshd->22
- Jenkins->8080
sudo mkdir -p /data/jenkins/logs
sudo chmod -R 777 /data/jenkins
docker run -d \
--env LANG=en_US.UTF-8 \
--env TZ=Asia/Shanghai \
-e PUBLIC_STR="$(<~/.ssh/[email protected])" \
-p 1022:22 \
-p 1808:8080 \
-v /data/jenkins/:/var/lib/jenkins/.jenkins/ \
-v /data/jenkins/logs:/var/log/jenkins/ \
-h jenkins \
--name jenkins \
fifilyu/jenkins:latest
# 目录降级读写权限
sudo chmod 755 /data/jenkins /data/jenkins/logs
# 使用容器内的jenkins用户和组的id重置目录用户组
uid=$(docker exec -it jenkins bash -c 'id -u jenkins' | tr -d '\r')
gid=$(docker exec -it jenkins bash -c 'id -g jenkins' | tr -d '\r')
sudo chown -R ${uid}:${gid} /data/jenkins
# 确认重置效果
ls -dln /data/jenkins && ls -al /data/jenkins
必须重启容器,否则容器无法读写映射目录
docker restart jenkins
sudo cat /data/jenkins/secrets/initialAdminPassword