在Jenkins中,我想了解为什么"docker ps"没有在我的容器内运行,尽管我编辑了我的Jenkins文件,像这样:
podTemplate(serviceAccount: 'jenkins', containers: [
containerTemplate(
name: 'docker',
image: 'docker',
resourceRequestCpu: '100m',
resourceLimitCpu: '300m',
resourceRequestMemory: '300Mi',
resourceLimitMemory: '500Mi',
command: 'cat',
privileged: true,
ttyEnabled: true
)
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]
) {
node(POD_LABEL) {
stage('Check running containers') {
container('docker') {
sh 'hostname'
sh 'hostname -i'
sh 'docker --version'
sh 'docker ps'
}
}
在我启动我的管道后,我总是有这样的消息:unix:///var/运行/docker.sock。
docker守护进程是否运行?由于
它必须有类似于PS运行docker命令的结果。
即使你在docker容器中运行Jenkins,你也必须在里面安装docker。
创建一个新的Dockerfile并在里面安装docker的最好方法。
FROM jenkins/jenkins
ARG HOST_UID=1004
ARG HOST_GID=999
USER root
RUN apt-get -y update &&
apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common &&
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - &&
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable" &&
apt-get update &&
apt-get -y install docker-ce docker-ce-cli containerd.io
RUN curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
&& chmod +x /usr/local/bin/docker-compose
&& ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
&& curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
RUN echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list
&& apt-get -y update
&& apt install -y kubectl
RUN usermod -u $HOST_UID jenkins
RUN groupmod -g $HOST_GID docker
RUN usermod -aG docker jenkins
USER jenkins
为了清晰起见,如果你部署到Kubernetes或使用docker-compose,你还需要在容器中使用kubectl和docker-compose。如果没有,你可以从上面的Dockerfile中删除安装。