gpt4 book ai didi

node.js - Jenkins - docker : not found

转载 作者:行者123 更新时间:2023-12-02 19:48:21 24 4
gpt4 key购买 nike

我对 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com