官方jenkins/jnlp-slave镜像默认不包含docker、kubectl,在jenkins+k8s配置动态节点时如果用到这两个命令会报错,本文章用于介绍怎么打包进去相关命令
dockerfile如下
#jenkins/jnlp-slave为官方镜像,版本可自行替换
FROM jenkins/jnlp-slave:4.13.3-1-jdk11
USER root
#修改debia源
RUN echo "deb http://mirrors.163.com/debian/ buster main" > /etc/apt/sources.list && \
echo "deb http://mirrors.163.com/debian/ buster-updates main non-free contrib" >> /etc/apt/sources.list && \
echo "deb http://mirrors.163.com/debian-security/ buster/updates main non-free contrib" >> /etc/apt/sources.list
#安装docker相关依赖
RUN apt-get update && \
apt-get -y install apt-transport-https ca-certificates curl gnupg2 apt-utils lsb-release software-properties-common && \
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/debian/gpg | apt-key add - && \
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/debian $(lsb_release -cs) stable" && \
apt-get -y update && \
apt-get -y install docker-ce
#安装kubectl
#这里我自己手动下载到服务器上传了,也可以自己修改一下dockerfile中配置一下curl -LO https://dl.k8s.io/release/v1.30.0/bin/linux/amd64/kubectl
下载上传
COPY kubectl /root/
RUN install -o root -g root -m 0755 /root/kubectl /usr/local/bin/kubectl
编辑完成后build即可
docker build -t zcm-slave .
参考链接: