node.js - Jenkins - docker : not found

标签 node.js docker jenkins raspberry-pi

我对 docker 和 jenkins 很陌生,但想看看我是否可以在我的树莓派上自动部署和运行 Node 应用程序。在一个理想的世界里,我想让 Jenkins 从 github 上下载代码,使用 jenkinsfile 和 dockerfile 来构建和运行 docker 镜像(希望这是可能的)。

Jenkins 文件

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} . ' 
            }
        }
    }
}

docker 文件
 # 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"]

但是,当我尝试在 jenkins 中运行它时,出现以下错误:../script.sh: docker: not found。这似乎适用于任何 docker 命令。我实际上尝试运行以“sudo”开头的其他一些命令,但它提示 sudo: not found。是否缺少步骤或者我试图以不正确的方式做某事。 (注意:docker 安装在树莓派上。我可以使用 jenkins 用户登录并执行 docker 命令。它只是无法通过 web ui 工作)任何建议将不胜感激。

谢谢!

最佳答案

显然这部分打破了它:

agent {
    dockerfile true
}

当我设置这个:
agent any

它完成了构建,包括没有任何问题的 docker 命令。我想我只是不明白那件作品是如何工作的。任何解释都会有所帮助!

关于node.js - Jenkins - docker : not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62295084/

相关文章:

node.js - docker桥接本地主机端口

ruby - Docker:每当我需要添加软件时,是否需要从头开始重建容器?

jenkins - 无法在 Jenkins 配置中添加 SSH key

node.js - 在azure上部署React应用程序

javascript - 运行应用程序时使用 multer 导致错误

docker - Jenkins管道: update image before docker. image().inside()

ruby - 如何在 jenkins slave 上用 watir 运行 ruby​​ 测试?

node.js - 来自 Mongoose 方法的新文档

javascript - 使用 Typescript 执行 API

jenkins - Okta 无法访问 jenkins 服务器