使用Docker安装Jenkins,并能够在该Jenkins中使用Docker

1. 构建Dockerfile 试错1

参考https://medium.com/@manav503/how-to-build-docker-images-inside-a-jenkins-container-d59944102f30

按照文章里所介绍的,实现在Jenkins容器环境中依然能够调用Docker,需要做到以下几步

  1. 下载Jenkins镜像
  2. 将环境中的docker.socket映射到Jenkins中部
  3. 在Jenkins镜像中安装docker客户端,调用docker.socket

为此,该博客构建的Dockerfile如下

from jenkinsci/jenkins:lts
 
USER root
RUN apt-get update -qq \
    && apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common 
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) \
   stable"
RUN apt-get update  -qq \
    && apt-get install docker-ce=17.12.1~ce-0~debian -y
RUN usermod -aG docker jenkins

然而我在实践的时候,发现如下问题

安装的时候没有任何输出

这是由于命令行指令中有-qq

在 apt-get update -qq这个命令中,-qq是一个选项名。这是APT命令行工具apt-get的一个参数。它的含义是"无视’-q’选项,除了错误之外,什么都不输出"。

再简单点说,就是当你运行带有-qq参数的apt-get update命令时,这个命令会在后台默默。它只有在遇到错误时才会输出信息,其他时候它都会默默工作,不会打印任何多余的信息。

执行update的时候总是error

首先我采取了换源策略,参考的博客是https://blog.csdn.net/weixin_45067618/article/details/122234387

使用的指令如下

# 查看内部软件源
cat /etc/apt/sources.list

# 查看系统版本
cat /etc/os-release
# PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
# NAME="Debian GNU/Linux"
# VERSION_ID="9"
# VERSION="9 (stretch)"
# ID=debian
# HOME_URL="https://www.debian.org/"
# SUPPORT_URL="https://www.debian.org/support"
# BUG_REPORT_URL="https://bugs.debian.org/"

然后根据系统版本,去清华大学镜像(https://mirrors.tuna.tsinghua.edu.cn/help/debian/)或者阿里云镜像(https://developer.aliyun.com/mirror/debian?spm=a2c6h.13651102.0.0.3e221b11vzU4iS)寻找对应版本的镜像源,然后替换sources.list的内容就可以

然而,我发现还是总会报错debian 9 apt update失败 (404 ign: E: W: N:)
后来查阅博客https://blog.csdn.net/vipdafei/article/details/130930882,才发现,原来debian 9的源已经停止维护了

从2023年4月23日起,debian9的源包地址更换至新地址。

新地址如下:

deb http://archive.debian.org/debian/ stretch main contrib non-free
deb-src http://archive.debian.org/debian/ stretch main contrib non-free
deb http://archive.debian.org/debian-security/ stretch/updates main contrib non-free
deb-src http://archive.debian.org/debian-security/ stretch/updates main contrib non-free
deb http://archive.debian.org/debian/ stretch-backports main contrib non-free

将上述内容输入到sources.list就可以正常更新了

执行最后一步apt-get install docker-ce=17.12.1ce-0debian -y的时候报错debconf: unable to initialize frontend: Dialog

参考https://blog.csdn.net/jiangjiang_jian/article/details/88822981

是因为在使用apt-get安装依赖时,可能会有对话框,制作镜像时如果不选择会导致失败。
解决方案:在Dockerfile中增加一句:

ENV DEBIAN_FRONTEND noninteractive

因此,在修改之后,Dockerfile的指令变成了这样

from jenkinsci/jenkins:lts
 
USER root

ADD ./sources.list /etc/apt/
#RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list
ENV DEBIAN_FRONTEND noninteractive

RUN cat /etc/os-release &&  cat /etc/apt/sources.list &&  apt-get update -qq\
    && apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | apt-key add -
RUN add-apt-repository \
   "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/debian/ \
   $(lsb_release -cs) \
   stable"
RUN apt-get update -qq\
    && apt-get install docker-ce=17.12.1~ce-0~debian -y
RUN usermod -aG docker jenkins

但还是无法安装,因为版本不对

改成上面这样,还是无法安装,提示Docker Desktop requires a newer WSL kernel version。因为我们用的jenkins版本不对。

  1. jenkinsci/jenkins:这是旧的Jenkins Docker镜像的名称。它是由Jenkins社区维护和发布的。早些年,Jenkins项目在jenkinsci这个Docker Hub命名空间下发布它们的官方镜像。

  2. jenkins/jenkins:这是新的Jenkins Docker镜像的名称。同样,它也是由Jenkins社区维护和发布的。不过,从2017年开始,Jenkins项目将官方镜像的发布位置从jenkinsci命名空间迁移到了jenkins命名空间下。

上述参考的博客都太老了,因此有必要更新了

2. 构建Dockerfile 新版本

新版本的Dockerfile如下所示

其中./sources.list来自于清华大学镜像https://mirrors.tuna.tsinghua.edu.cn/help/debian/,选的是Debian 12版本

from jenkins/jenkins
 
USER root

ADD ./sources.list /etc/apt/
ENV DEBIAN_FRONTEND noninteractive

RUN cat /etc/os-release &&  cat /etc/apt/sources.list &&  apt-get update -qq\
    && apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | apt-key add -
RUN add-apt-repository \
   "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/debian/ \
   $(lsb_release -cs) \
   stable"
RUN apt-get update -qq\
    && apt-get install docker-ce -y
RUN usermod -aG docker jenkins

3. 搭建Jenkins服务

搭建Jenkins服务可以参考我之前的博客https://blog.csdn.net/weixin_42763696/article/details/134499518

构建自由风格的流水线,执行脚本docker container ls即可
在这里插入图片描述

相关推荐

最近更新

  1. SQL Server设置端口:跨平台指南

    2024-01-30 06:30:07       0 阅读
  2. 指定版本ceph-common安装

    2024-01-30 06:30:07       0 阅读
  3. 中科海讯 C++初级研发工程师笔试题目

    2024-01-30 06:30:07       0 阅读
  4. vue3的常用 Composition API有哪些?

    2024-01-30 06:30:07       1 阅读
  5. Linux系统基础命令行指令——Ubuntu

    2024-01-30 06:30:07       0 阅读
  6. 【Android高级UI】计算不规则图形面积

    2024-01-30 06:30:07       0 阅读
  7. Python库 - PyMC3

    2024-01-30 06:30:07       0 阅读
  8. C语言中关键字

    2024-01-30 06:30:07       0 阅读
  9. ios CCPlistFileWritter.m

    2024-01-30 06:30:07       0 阅读
  10. C#实现Winform程序右下角弹窗消息提示

    2024-01-30 06:30:07       0 阅读

热门阅读

  1. layui-vue + Flask 实现 Table 排序显示

    2024-01-30 06:30:07       39 阅读
  2. pfc001 Not enough information

    2024-01-30 06:30:07       27 阅读
  3. 如何将抖音API应用于抖音视频的录制和上传

    2024-01-30 06:30:07       113 阅读
  4. Python学习之路-Django基础:类视图与中间件

    2024-01-30 06:30:07       37 阅读
  5. Excel-Apache POI

    2024-01-30 06:30:07       23 阅读
  6. Spring设计模式之简单工厂模式

    2024-01-30 06:30:07       40 阅读
  7. 学习鸿蒙基础(1)

    2024-01-30 06:30:07       35 阅读
  8. pytest封装请求类

    2024-01-30 06:30:07       32 阅读
  9. SpringMVC

    SpringMVC

    2024-01-30 06:30:07      37 阅读