Docker方式部署Jenkins

环境准备:

Centos 7.4

Docker-ce, Docker的安装方式就不说了

步骤:

1. 创建Nexus的持久化目录

useradd jenkins && mkdir -p /data/jenkins-data && chown -R jenkins /data/jenkins-data

2. 将服务文件添加到systemd中,这些就可以随系统一起启动了

#vi /etc/systemd/system/jenkins.service 

[Unit]
Description=Jenkins 1.22.0
Documentation=https://jenkins.io/zh/doc/book/installing/#setup-wizard
After=network.target docker.service
Requires=docker.service

[Service]
RestartSec=10
Restart=always

# Modify IP6_PREFIX to match network config

Environment="NAME=jenkins"
Environment="DATA_DIR=/data/jenkins-data"
Environment="IMG=jenkinsci/blueocean:1.22.0"
Environment="PORT=8080:8080/tcp"


# http://www.freedesktop.org/software/systemd/man/systemd.unit.html

# Clean-up bad state if still hanging around
#ExecStartPre=-/usr/bin/docker rm -f $NAME

# Attempt to pull new image for security updates
ExecStartPre=-/usr/bin/docker pull $IMG

# IPv6: Ensure forwarding is enabled on host's networking stack (hacky)
# Would be nice to use systemd-network on the host, but this doens't work
# http://lists.freedesktop.org/archives/systemd-devel/2015-June/032762.html
ExecStartPre=/bin/sh -c 'test -z "$IP6_PREFIX" && exit 0; sysctl net.ipv6.conf.all.forwarding=1'

# Main process
ExecStart=/usr/bin/docker run --rm -v ${DATA_DIR}:/var/jenkins_home  --name ${NAME} -p ${PORT} ${IMG}

# IPv6: Add static route for IPv6 after it starts up
ExecStartPost=/bin/sh -c 'test -z "${IP6_PREFIX}" && exit 0; sleep 1; ip route replace ${IP6_PREFIX} via $(docker inspect -f "{{ .NetworkSettings.GlobalIPv6Address }}" $NAME ) dev docker0'

# IPv6: Clean-up
ExecStopPost=/bin/sh -c 'test -z "$IP6_PREFIX" && exit 0; ip route del $IP6_PREFIX dev docker0'

[Install]
WantedBy=multi-user.target

3. 加入系统自启动并启动服务

systemctl daemon-reload && systemctl enable jenkins && systemctl start jenkins

4. 访问系统,第一次访问的用户名为:admin 密码在宿主机的:/data/jenkins-data/secrets/initialAdminPassword

5. 访问系统,http://10.128.12.12:8080/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值