【问题标题】:Docker Build fails in GCP Cloud Build - but successful in localhostDocker Build 在 GCP Cloud Build 中失败 - 但在 localhost 中成功
【发布时间】:2020-01-24 21:23:08
【问题描述】:

以下 Dockerfile 在 GCP Cloud Build 中的 npm install --production 失败

FROM node:10.15.3-slim 

RUN sh -c 'apt-get update && apt-get install -y build-essential && apt-get install -y python'

COPY src /home/$user/
WORKDIR /home/$user

RUN npm install --production

CMD [ "npm", "start" ]

这是 package.json

{
    "name": "generic-cloud-node-sql",
    "version": "1.0.0",
    "private": true,
    "scripts": {
        "start": "node ./bin/www",          
    },
    "dependencies": {
        "@google-cloud/bigquery": "^4.0.0",
        "@google-cloud/storage": "^2.5.0",
        "body-parser": "*",
        "cron": "^1.7.1",
        "dateformat": "^3.0.2",
        "express": "*",
        "form-data": "*",
        "multer": "^1.4.1",
        "njwt": "*",
        "promise-mysql": "^3.3.1",
        "request": "^2.88.0",
        "request-ip": "^2.1.3",
        "throw.js": "*",
        "bcrypt": "^3.0.6",
        "winston": "*",
        "winston-gke": "*"
    },
    "devDependencies": {
        "chai": "^4.2.0",
        "mocha": "^5.2.0",
        "chai-http": "*"
    }
}

当它尝试安装带有消息的bcrypt 时失败

Step #1: > bcrypt@3.0.6 install /home/node_modules/bcrypt
Step #1: > node-pre-gyp install --fallback-to-build
Step #1:
Step #1: node-pre-gyp WARN Using request for node-pre-gyp https download
Step #1: node-pre-gyp ERR! Completion callback never invoked!
Step #1: node-pre-gyp ERR! System Linux 4.15.0-1044-gcp
Step #1: node-pre-gyp ERR! command "/usr/local/bin/node" "/home/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
Step #1: node-pre-gyp ERR! cwd /home/node_modules/bcrypt
Step #1: node-pre-gyp ERR! node -v v10.15.3
Step #1: node-pre-gyp ERR! node-pre-gyp -v v0.12.0
Step #1: node-pre-gyp ERR! This is a bug in `node-pre-gyp`.
Step #1: node-pre-gyp ERR! Try to update node-pre-gyp and file an issue if it does not help:

但是当我在本地运行docker build 时,上面的 Dockerfile 和 package.json 可以成功运行。

  • 没有 node_modules 复制到 docker 映像中
  • 没有将 package_lock.json 复制到 docker 映像中
  • 构建过程开始失败,但未更改任何相关文件(Dockerfile、package.json 等)

可能是什么问题?

【问题讨论】:

  • 明白,我的错,我读得太快了你的 COPY 行。
  • 这里没有错。我建议你再试一次。如果您没有安装已经在 build-essential 中安装的 C/CXX 编译器,bcrypt 通常会失败。
  • 它在 cloudbuild 中失败并显示上述消息。

标签: node.js docker npm google-cloud-platform google-cloud-build


【解决方案1】:

这看起来更像是 node-pre-gyp 的问题,而不是 Cloud Build 的问题。我在 GitHub 上找到了与您遇到的问题相匹配的 this 问题。绝对值得一看。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-29
    • 2021-03-06
    • 2022-11-16
    • 2020-04-05
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多