1. 获取镜像

  1. # 查看可用的稳定版本
  2. sudo docker search jenkins
  3. sudo docker pull jenkins
  4. sudo docker image ls |grep jenkins

2. 创建数据卷

  1. sudo mkdir -p /opt/jenkins
  2. sudo chown -R 1000:1000 /opt/jenkins

3. 启动容器

  1. # 方法1
  2. sudo docker run -d --name jenkins \
  3. -p 28080:8080 \
  4. -v /opt/jenkins:/var/jenkins_home \
  5. jenkins
  6. # 方法2
  7. sudo docker run -d --name jenkins \
  8. -p 28080:8080 \
  9. -p 50000:50000 \
  10. -u root \
  11. -v /opt/jenkins:/var/jenkins_home \
  12. jenkins
  13. sudo docker start jenkins
  14. sudo docker restart jenkins
  15. sudo docker stop jenkins
  16. sudo docker rm jenkins

4. 验证

  1. # 进入终端
  2. docker exec -it jenkins /bin/bash
  3. # 获取密码
  4. cat /var/jenkins_home/secrets/initialAdminPassword
  5. # 查看日志
  6. sudo docker logs jenkins
  7. sudo docker logs -f -t --tail=50 jenkins
  8. # 查看网络
  9. sudo docker network ls
  10. sudo docker inspect jenkins

Web UIhttp://192.168.0.99:28080