环境
Ubuntu 22.04 LTS
Docker 27.2.1
描述
部署 Jenkins,Bind 绑定挂载方式,Port 使用 Published,使用本机 Docker,设置 Docker 使用内网加速、私有 http 仓库。
所有操作均使用 root 用户,执行目录为 /usr/local/docker/jenkins/
步骤
设置权限
# 若本机只有 root 用户,无普通用户需执行
useradd -u 1000 docker
chown 1000:root /var/run/docker.sock
chown -R 1000:root data
正确编写末尾相关文件(无则创建)后,刷新 Docker 配置
systemctl daemon-reload
systemctl restart docker
stack 方式部署
docker stack deploy -c stack-compose.yml jks-stack
查看 Jenkins 日志,获取登录密码
docker logs jks-stack_jenkins1.1.*
# 提示信息如下
Please use the following password to proceed to installation:
ABCD1234
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
相关文件
docker-proxy.conf
路径:/etc/systemd/system/docker.service.d/docker-proxy.conf
Environment="HTTP_PROXY=http://IP地址:端口"
Environment="HTTPS_PROXY=http://IP地址:端口"
Environment="NO_PROXY=localhost,127.0.0.1,IP端/掩码,reg.yudelei.com"
daemon.json
路径:/etc/docker/daemon.json
{
"insecure-registries": ["http://IP地址或域名:80"]
}
stack-compose.yml
路径:/usr/local/docker/jenkins/
version: "3.8"
services:
jenkins1:
image: jenkins/jenkins:2.462.2-lts
hostname: "jenkins1"
ports:
- target: 8080
published: 18002
- target: 50000
published: 18003
volumes:
- ./data/:/var/jenkins_home/
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- /etc/docker/daemon.json:/etc/docker/daemon.json # 需更改,更换源或设置私有仓库等,若不使用可注释
deploy:
replicas: 1
placement:
constraints:
- node.hostname == NODE名称 # 需更改
restart_policy:
condition: on-failure
max_attempts: 3
networks:
- net73
networks:
net73:
driver: overlay