前置条件
假设机器上已经安装了Docker和Docker-Compose。
如果还未安装,请参考Docker官方文档进行安装。
安装步骤
克隆或复制 jenkins 目录到机器上。
或者创建jenkins文件夹,文件夹下存放一下三个文件:
docker-compose.yml:
version: '3'
services:
jenkins:
image: 'jenkins/jenkins:lts'
container_name: jenkins
restart: always
ports:
- '8080:8080'
- '50000:50000'
volumes:
- '/var/jenkins_home:/var/jenkins_home'
docker_run_install_jenkins.sh:
#!/bin/bash
docker run --name jenkins \
-d \
-p 8080:8080 \
-p 50000:50000 \
-v /var/jenkins_home:/var/jenkins_home \
--restart always \
jenkins/jenkins:lts
pre_install_jenkins.sh:
#!/bin/bash
mkdir -p /var/jenkins_home
chown -R 1000:1000 /var/jenkins_home
文件结构目录:
在jenkins目录运行以下命令:
# 给脚本授权
chmod u+x *.sh
# 创建Jenkins数据目录(用作持久卷)
./pre_install_jenkins.sh
# 启动Jenkins容器
docker-compose up -d
运行 docker logs -f jenkins
查看Jenkins日志。
找到Jenkins Initial Password的日志,比如:
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
<Initial Admin Password>
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
访问Jenkins网址http://[server_ip]:8080,输入上面生成的初始密码,按照提示安装到成功完成。
非本人原创,但是亲自实验可用。