自动部署第一期 docker-compose 安装 jenkins

jenkins

前言

Jenkins是一款开源的CI&CD软件,用于自动化各种开发任务,包括构建、测试和部署软件等。使我们的发布流程变得更加透明,简易。

安装

推荐使用docker-compose安装。docker-compose专栏

# 在home目录下创建jenkins文件夹专门用来存放挂载的
root@VM-8-11-ubuntu:/home# mkdir jenkins  
root@VM-8-11-ubuntu:/home# cd jenkins
# 创建docker-compose文件
root@VM-8-11-ubuntu:/home/jenkins# vim docker-compose.yml
# docker-compose.yml的文件内容
version: "3"
services:
  jenkins:
    image: jenkinsci/blueocean
    container_name: jenkins
    ports:
      - "8090:8080"
      - "50000:50000"
    volumes:
      - ./jenkins-data:/var/jenkins_home:ro
      - ./var/run/docker.sock:/var/run/docker.sock:rw
    restart: always
    networks:
      - default
# 启动容器
root@VM-8-11-ubuntu:/home/jenkins# docker-compose up
Creating network "jenkins_default" with the default driver
Pulling jenkins (jenkinsci/blueocean:)...
latest: Pulling from jenkinsci/blueocean
97518928ae5f: Pull complete
f4d84728e541: Pull complete
419d112ff4fa: Pull complete
ecf8c1881f75: Pull complete
78b59c3bfdb7: Pull complete
2ff43df4e763: Pull complete
aac7818be7cc: Pull complete
2913a3e94ae4: Pull complete
f75b1dac4ec0: Pull complete
3d3fbe6f1850: Pull complete
07ef919d711b: Pull complete
5b96e9c30f6a: Pull complete
83dcd37be04b: Pull complete
6beb8929489c: Pull complete
476e95021232: Pull complete
9add339bd1dd: Pull complete
16ec9218e99c: Pull complete
a99dba90c973: Pull complete
Digest: sha256:5cb8c9ae61ac71ad8a6631dc5b0bf58c0cbfe1b1b511da45134213396c8056f8
Status: Downloaded newer image for jenkinsci/blueocean:latest
Creating jenkins ... done
# 查看容器状态
root@VM-8-11-ubuntu:/home/jenkins# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS                                  PORTS                                                   NAMES
5f924c8e4864   jenkinsci/blueocean   "/sbin/tini -- /usr/…"   6 seconds ago   Restarting (1) Less than a second ago 

# 我们看到容器一直在重启 说明报错了 我们查看下日志
root@VM-8-11-ubuntu:/home/jenkins# docker logs jenkins
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Read-only file system
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions? 
# 将docker-compose.yml 的volumes中的 :ro 改为:rw
root@VM-8-11-ubuntu:/home/jenkins#
 

这时我们看到是有报错的,这时我们就需要docker-compose.yml的挂载只读设置了

# 可以看到只读 这时我们就将docker-dompose.yml 的:ro 改为 :rw 就行了
volumes:
      - ./jenkins-data:/var/jenkins_home:ro
root@VM-8-11-ubuntu:/home/jenkins# docker stop jenkins
jenkins
root@VM-8-11-ubuntu:/home/jenkins# docker rm jenkins
jenkins
# 重新启动
root@VM-8-11-ubuntu:/home/jenkins# docker-compose up
Creating jenkins ... done
Attaching to jenkins
jenkins    | touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
jenkins    | Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
# 我们发现还是报错,这个时候设置 sudo chown -R 1000 jenkins-data
root@VM-8-11-ubuntu:/home/jenkins# sudo chown -R 1000 jenkins-data/
# 重启jenkins
root@VM-8-11-ubuntu:/home/jenkins# docker restart jenkins
jenkins

root@VM-8-11-ubuntu:/home/jenkins# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS         PORTS                                                                                      NAMES
de1b205ada95   jenkinsci/blueocean   "/sbin/tini -- /usr/…"   5 minutes ago   Up 2 seconds   0.0.0.0:50000->50000/tcp, :::50000->50000/tcp, 0.0.0.0:8090->8080/tcp, :::8090->8080/tcp   jenkins

这个时候看到已经启动成功了,直接访问:8090 就可以了
在这里插入图片描述

/var/jenkins_home/secrets/initialAdminPassword 这是容器的目录路径,对应宿主机就是挂载的目录
# 获取本地的密码填进 上图的管理员密钥中就行了
root@VM-8-11-ubuntu:/home/jenkins# cd jenkins-data/secrets/
root@VM-8-11-ubuntu:/home/jenkins/jenkins-data/secrets# cat initialAdminPassword
e4439f7d3c3244d5849156079be19591

这个时候就完全安装好了,接下来将我们的项目部署上去就行了,可以查看下期博客。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值