1. 获取镜像
# 查看可用的稳定版本
sudo docker search jenkins
sudo docker pull jenkins
sudo docker image ls |grep jenkins
2. 创建数据卷
sudo mkdir -p /opt/jenkins
sudo chown -R 1000:1000 /opt/jenkins
3. 启动容器
# 方法1
sudo docker run -d --name jenkins \
-p 28080:8080 \
-v /opt/jenkins:/var/jenkins_home \
jenkins
# 方法2
sudo docker run -d --name jenkins \
-p 28080:8080 \
-p 50000:50000 \
-u root \
-v /opt/jenkins:/var/jenkins_home \
jenkins
sudo docker start jenkins
sudo docker restart jenkins
sudo docker stop jenkins
sudo docker rm jenkins
4. 验证
# 进入终端
docker exec -it jenkins /bin/bash
# 获取密码
cat /var/jenkins_home/secrets/initialAdminPassword
# 查看日志
sudo docker logs jenkins
sudo docker logs -f -t --tail=50 jenkins
# 查看网络
sudo docker network ls
sudo docker inspect jenkins
Web UI:http://192.168.0.99:28080