简体   繁体   English

Jenkins - docker:未找到

[英]Jenkins - docker: not found

I'm pretty new to do docker and jenkins but wanted to see if I could get a node app automatically deployed and running on my raspberry pi.我是 docker 和 jenkins 的新手,但想看看我是否可以在我的树莓派上自动部署和运行节点应用程序。 In an ideal world, I'd like to have Jenkins pull down code from github, use a jenkinsfile and dockerfile to build and run the docker image (hopefully this is possible).在理想情况下,我希望 Jenkins 从 github 中提取代码,使用 jenkinsfile 和 dockerfile 构建并运行 docker 图像(希望这是可能的)。

jenkinsfile詹金斯文件

pipeline {
    agent {
        dockerfile true
    }
    environment {
        CI = 'true' 
        HOME = '.'
    }
    stages {
        stage('Install dependencies') {
            steps {
                sh 'npm install'
            }
        }
        stage('Test') { 
            steps {
                sh './scripts/test' 
            }
        }
        stage('Build Container') { 
            steps {
                sh 'docker build -t test-app:${BUILD_NUMBER} . ' 
            }
        }
    }
}

dockerfile dockerfile

 # Create image based on the official Node image
FROM node:12

# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app

# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app

# Copy dependency definitions
COPY package.json /usr/src/app

# Install dependecies
RUN npm install

# Get all the code needed to run the app
COPY . /usr/src/app

# Expose the port the app runs in
EXPOSE 3000

# Serve the app
CMD ["npm", "start"]

However, when I try to run this in jenkins, I get the following error: ../script.sh: docker: not found .但是,当我尝试在 jenkins 中运行它时,出现以下错误: ../script.sh: docker: not found This seems to be the case for any docker command.这似乎是任何 docker 命令的情况。 I actually tried running some other command starting with 'sudo' and it complained that sudo: not found .我实际上尝试运行其他一些以“sudo”开头的命令,它抱怨说sudo: not found Is there a step missing or am I trying to do something in an incorrect way.是否缺少步骤,或者我是否尝试以不正确的方式做某事。 (NOTE: docker is installed on the raspberry pi. I can log in with the jenkins user and execute docker commands. It just doesn't work through the web ui) Any advice would be appreciated. (注意:docker 安装在树莓派上。我可以使用 jenkins 用户登录并执行 docker 命令。它只是无法通过 web ui 工作)任何建议将不胜感激。

Thanks!谢谢!

Apparently this section was breaking it:显然这部分打破了它:

agent {
    dockerfile true
}

When I set this:当我设置这个时:

agent any

it finished the build, including docker commands without any issues.它完成了构建,包括 docker 个命令,没有任何问题。 I guess I just don't understand how that piece works.我想我只是不明白那件作品是如何运作的。 Any explanations would be helpful!任何解释都会有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM