首页 > 其他分享 >解决pipline找不到docker命令:/Users/beck/.jenkins/workspace/locust_test@tmp/durable-884e1b18/script.sh: line

解决pipline找不到docker命令:/Users/beck/.jenkins/workspace/locust_test@tmp/durable-884e1b18/script.sh: line

时间:2022-12-24 12:33:23浏览次数:59  
标签:tmp Pipeline Users locust beck jenkins docker

问题一:/Users/beck/.jenkins/workspace/locust_test@tmp/durable-884e1b18/script.sh: line 1: docker: command not found

完整的pipeline如下,在docker hub上我打包了locust的运行环境locust:v1,这时候通过本地的jenkins去驱动本地的docker拉取镜像

pipeline {
    agent {
        docker { image 'docker.io/beck123/locust:v1'}
    }
    
    stages {
        stage('Test') {
            steps {
                sh 'docker images'
            }
        }
    }
}

实际上发现build的console出现报错

Started by user admin
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /Users/beck/.jenkins/workspace/locust_test
[Pipeline] {
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . docker.io/beck123/locust:v1
/Users/beck/.jenkins/workspace/locust_test@tmp/durable-884e1b18/script.sh: line 1: docker: command not found
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker pull docker.io/beck123/locust:v1
/Users/beck/.jenkins/workspace/locust_test@tmp/durable-ef3eab12/script.sh: line 1: docker: command not found
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE

解决办法

参考stack overflow上的这篇文章:docker command not found in local jenkins multi branch pipeline,里面说到

The solution is to add the following line into the /usr/local/Cellar/jenkins-lts/2.176.3/homebrew.mxcl.jenkins-lts.plist file so that Jenkins able to find the docker command from the host machine.

<key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin/:/Users/Kh0a/Library/Group\ Containers/group.com.docker/Applications/Docker.app/Contents/Resources/bin</string>
    </dict>

我本地的地址是:/usr/local/Cellar/jenkins-lts/2.346.3/homebrew.mxcl.jenkins-lts.plist,直接修改后然后brew services restart jenkins-lts即可

问题二:+ docker images /Users/beck/.jenkins/workspace/locust_test@tmp/durable-195d79d3/script.sh: 1: docker: not found [Pipeline] }

如果仔细看console的报错信息,就会发现这个命令是在容器内部执行的,容器内部没有安装docker,所以出错了

Started by user admin
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /Users/beck/.jenkins/workspace/locust_test
[Pipeline] {
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . docker.io/beck123/locust:v1

Error: No such object: docker.io/beck123/locust:v1
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker pull docker.io/beck123/locust:v1
v1: Pulling from beck123/locust
32de3c850997: Already exists
fa1d4c8d85a4: Already exists
c796299bbbdd: Already exists
81283a9569ad: Already exists
60b38700e7fb: Already exists
0f67f32c26d3: Already exists
e04be0d92e59: Already exists
b5052f164cdb: Already exists
e9c72aa5d062: Already exists
fa4d8dfca272: Already exists
3e38e9881935: Already exists
b2afa8015854: Already exists
Digest: sha256:75cd72c415c23fad7fd0bcab1397097ad49feea867376a68b61f502fb510af72
Status: Downloaded newer image for beck123/locust:v1
docker.io/beck123/locust:v1
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] **withDockerContainer**
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 501:20 -w /Users/beck/.jenkins/workspace/locust_test -v /Users/beck/.jenkins/workspace/locust_test:/Users/beck/.jenkins/workspace/locust_test:rw,z -v /Users/beck/.jenkins/workspace/locust_test@tmp:/Users/beck/.jenkins/workspace/locust_test@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** docker.io/beck123/locust:v1 cat
$ docker top 62a42ab5460e7ebd731de892a43a982231272f764471ead0606ace2688b90bda -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] sh
+ docker images
/Users/beck/.jenkins/workspace/locust_test@tmp/durable-195d79d3/script.sh: 1: docker: not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 62a42ab5460e7ebd731de892a43a982231272f764471ead0606ace2688b90bda
$ docker rm -f --volumes 62a42ab5460e7ebd731de892a43a982231272f764471ead0606ace2688b90bda
[Pipeline] // **withDockerContainer**
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE

这时候可以输出下python的版本,可以看到成功了

pipeline {
    agent {
        docker { image 'docker.io/beck123/locust:v1'}
    }
    
    stages {
        stage('Test') {
            steps {
                sh '''
                    python --version
                   '''
            }
        }
    }
}
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 501:20 -w /Users/beck/.jenkins/workspace/locust_test -v /Users/beck/.jenkins/workspace/locust_test:/Users/beck/.jenkins/workspace/locust_test:rw,z -v /Users/beck/.jenkins/workspace/locust_test@tmp:/Users/beck/.jenkins/workspace/locust_test@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** docker.io/beck123/locust:v1 cat
$ docker top a29a24779a958fbece3102def3f1bda29cf80f467672609f84273aae27c7b480 -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] sh
+ python --version
Python 3.8.16
+ ls -al
total 4

标签:tmp,Pipeline,Users,locust,beck,jenkins,docker
From: https://www.cnblogs.com/my_captain/p/17002748.html

相关文章

  • 将镜像上传到Docker Hub中央仓库中
    首先创建一个镜像,点击:​​创建一个简单的Docker镜像​​1.先注册帐号 ​​https://hub.docker.com/​​         2.将镜象推上去[root@localhostdocker]#docker......
  • 44docker
    笔记dockerdockerDocker概述Docker安装Docker命令镜像命令容器命令操作命令....Docker镜像容器数据卷DockerFileDocker网络原理IDEA整合D......
  • docker-compose部署kafka集群
    vim  docker-compose.ymlversion:'3'services:zookeeper:image:zookeeperports:-2182:2181restart:alwayskafka1:image:wu......
  • # Win10为知笔记Docker镜像部署 -v /wiz/storage问题解决
    Win10为知笔记Docker镜像部署-v/wiz/storage问题解决用了很长一段时间的为知笔记,客户端体验还行,服务端笔记同步体验不佳。准备用Docker自己搭一个服务端。环境:操作......
  • CentOS安装docker
    1、配置要求系统:CentOS7及以上Linux内核:官方建议3.10以上1.1、查看内核版本uname-r 1.2、卸载旧版本docker(如果之前安装过则需要卸载)yumre......
  • Spring Boot with Docker
    本指南将引导您完成构建码头工人​用于运行Spring引导应用程序的映像。我们从一个基本开始,并进行一些调整。然后我们展示了几个使用构建插件(用于Maven和Gradle)而不是.......
  • 使用docker-compose部署kafka
    1、拉取镜像dockerpullbitnami/zookeeper:latestdockerpullbitnami/kafka:latest2、下载docker-composecurl-Lhttps://get.daocloud.io/docker/compose/releases/down......
  • 折腾 Docker
    如果Windows主机无法ping通Docker容器中CentOS的IP地址,可能是因为容器和主机之间的网络设置问题。你可以尝试以下步骤来解决这个问题:查看Docker容器的网络模......
  • 实验2:Docker实验
    云计算技术与应用    石家庄铁道大学信息学院 实验2:Docker实验本次实验属于验证型实验,通过本次实验学生将掌握以下内容:1、了解Docker服务安装;2、掌握Docker镜......
  • docker swarm 服务/容器编排
    十年河东,十年河西,莫欺少年穷学无止境,精益求精根据上节搭建的集群环境:dockerswarm集群环境搭建【一主二从】本节来进行服务/容器编排1、在master管理者节点拉取nginx......