Jenkins声明性管道docker:命令未找到 [英] Jenkins Declarative pipeline docker: command not found
问题描述
我已经在计算机上本地安装了Jenkins.我从我的github存储库中提取了一些源代码,该存储库的根目录中有一个Docker文件.我想构建和放置docker image并将其推送到docker hub,但是构建失败并显示以下消息...
I have installed Jenkins locally on my machine. I pulling some source code from my github repository which has a Docker file in the root directory. I want to build and docker image and push it to docker hub but my build fails with the following message...
docker build -f myapp-web:latest . \n
/Users/Shared/Jenkins/Home/workspace/MyApp@tmp/durable-ee9851e9/script.sh: line 1: docker: command not found
pipeline {
agent any
tools {
maven 'maven_3.6.1'
jdk 'jdk8'
}
stages {
stage('Build') {
steps {
withMaven(maven: 'maven_3.6.1', mavenSettingsConfig: '5d7a8237-6d6a-4189-a907-518900dc7755') {
sh "mvn clean install "
}
}
}
stage('Build Image') {
steps {
script {
sh 'docker build -f myapp-web:latest .'
}
}
}
stage('Deploy Image') {
steps {
withDockerRegistry([credentialsId: "docker-hub", url: ""]) {
sh 'docker push myapp-web:latest'
}
}
}
}
}
Docker已在我的本地计算机上安装并运行,并且使用以下插件配置了Jenkins Docker管道 Docker插件
Docker is install and running on my local machine and Jenkins is configured with the following plugin Docker pipeline Docker plugin
任何想法都值得赞赏
推荐答案
如果通过管道获取docker: command not found
,尽管它已安装在运行管道的同一节点上,则需要确保管道正在读取正确的$PATH
环境,其中应该存在docker二进制文件.
If you are getting docker: command not found
through the pipeline although its already installed on the same node where the pipeline is running, you need to ensure that the pipeline is reading the correct $PATH
environment where the docker binary should be exist.
您提到的第二个问题
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
您需要将管道中正在使用的用户添加到docker组,以便它可以使用以下命令运行docker命令:
you need to add the user that is being used within the pipeline to the docker group so it can run docker commands using:
usermod -aG docker $USER
这篇关于Jenkins声明性管道docker:命令未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!