【问题标题】:React | Node application | Docker deployment反应 |节点应用 | Docker 部署
【发布时间】:2020-03-28 12:12:57
【问题描述】:

我对此有点陌生,已经创建了 react 前端和 Node 后端应用程序并尝试在 docker 中部署,但它抛出了以下错误。有人可以帮助我为什么要引用 python,以及为什么 couchbase 安装有问题吗?

Package.json 文件有

{
  "name": "XPress",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "antd": "^3.10.8",
    "axios": "^0.18.1",
    "body-parser": "^1.19.0",
    "cors": "2.8.5",
    "couchbase": "^2.6.11",
    "dva": "^2.4.1",
    "dva-loading": "^2.0.6",
    "express": "^4.17.1",
    "pg": "^7.18.2",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-scripts": "2.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app",
    "parser": "babel-eslint",
    "parserOptions": {
      "sourceType": "module",
      "allowImportExportEverywhere": true
    }
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

错误

TestUser-8681:Utility TestUser$ docker build . -t xpressimg
Sending build context to Docker daemon  434.4MB
Step 1/7 : FROM  node:alpine
 ---> 483343d6c5f5
Step 2/7 : WORKDIR /xpress
 ---> Using cache
 ---> fc35b4f51420
Step 3/7 : COPY package*.json ./
 ---> Using cache
 ---> 5593b2fe0b05
Step 4/7 : RUN npm install
 ---> Running in f00b67e0b069
> couchbase@2.6.11 install /xpress/node_modules/couchbase
> prebuild-install || node-gyp rebuild
prebuild-install WARN install unable to get local issuer certificate
gyp ERR! find Python
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON
gyp ERR! find Python checking if "python" can be used
gyp ERR! find Python - "python" is not in PATH or produced an error
gyp ERR! find Python checking if "python2" can be used
gyp ERR! find Python - "python2" is not in PATH or produced an error
gyp ERR! find Python checking if "python3" can be used
gyp ERR! find Python - "python3" is not in PATH or produced an error
gyp ERR! find Python
gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "/path/to/pythonexecutable"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:307:47)
gyp ERR! stack     at PythonFinder.runChecks (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:136:21)
gyp ERR! stack     at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:179:16)
gyp ERR! stack     at PythonFinder.execFileCallback (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:271:16)
gyp ERR! stack     at exithandler (child_process.js:310:5)
gyp ERR! stack     at ChildProcess.errorhandler (child_process.js:322:5)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
gyp ERR! stack     at onErrorNT (internal/child_process.js:467:16)
gyp ERR! stack     at processTicksAndRejections (internal/process/task_queues.js:84:21)
gyp ERR! System Linux 4.19.76-linuxkit
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /xpress/node_modules/couchbase
gyp ERR! node -v v13.12.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/react-scripts/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! couchbase@2.6.11 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the couchbase@2.6.11 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-03-28T03_12_19_475Z-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 1

感谢您在这方面的支持

根据提供的建议,我看到以下错误 将构建上下文发送到 Docker 守护进程 434.4MB [警告]:在以下位置找到空续行: 运行 apk 添加 --update-cache python python-dev py-pip build-base WORKDIR /xpress [警告]:空的续行将成为未来版本中的错误。 第 1/7 步:从节点:高山 ---> 483343d6c5f5 第 2/7 步:运行 apk add --update-cache python python-dev py-pip build-base WORKDIR /xpress ---> 在 e587974d8218 中运行 获取http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz 获取http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz 错误:不可满足的约束: /xpress(缺失): 要求:世界[/xpress] 工作目录(缺失): 要求:世界[WORKDIR] 命令 '/bin/sh -c apk add --update-cache python python-dev py-pip build-base WORKDIR /xpress' 返回一个非零代码:2

【问题讨论】:

    标签: node.js reactjs docker couchbase


    【解决方案1】:

    显然,node-gyp depends on a Python interpreter in the environment 和 couchbase 依赖于要安装的 node-gyp。您必须在 Docker 容器中安装 Python。

    考虑到你正在使用alpine:node,你可以通过apk安装它:

    RUN apk add --update-cache \
        python \
        python-dev \
        py-pip \
        build-base
    

    在运行npm install之前添加此命令。

    此示例取自此处:https://github.com/gliderlabs/docker-alpine/blob/master/docs/usage.md#example

    更新

    抱歉,我的回复不完整。您需要安装一些其他依赖项,并在运行 npm install 后将其删除。看看这个问题:https://github.com/mhart/alpine-node/issues/27#issuecomment-390187978

    请注意,npm install 在apk addapk del 之间运行,因此构建依赖项(例如python)不会捆绑在您的映像中

    RUN apk add --no-cache --virtual .build-deps make gcc g++ python \
     && npm install --production --silent \
     && apk del .build-deps
    

    【讨论】:

    • 感谢您的回复。我尝试了上面的建议,无法添加整个错误,所以我在原帖中添加了。我仍然看到一些错误。
    • 抱歉,我的回复不完整。您需要安装一些其他依赖项,并在运行 npm install 后将其删除。看看这个问题:github.com/mhart/alpine-node/issues/27#issuecomment-390187978
    • 再次感谢,镜像已构建,TestUser$ docker run ximghjgdddsk /xpress/node_modules/bindings/bindings.js:121 throw e; ^Error: Error loading shared library /xpress/node_modules/couchbase/build/Release/couchbase_impl.node: Exec格式错误,我最新的docker文件如下
    • FROM node:alpine # 创建应用程序目录 WORKDIR /xpress # 安装应用程序依赖项 # 使用通配符确保 package.json 和 package-lock.json 都被复制 # 在可用的地方(npm@5+ ) RUN apk add --no-cache --virtual .build-deps make gcc g++ python \ && npm install --production --silent \ && apk del .build-deps COPY package*.json ./ # 如果你正在构建您的生产代码 # RUN npm ci --only=production # Bundle app source COPY 。 . CMD [ "npm", "start" ] CMD [ "node", "server.js" ]
    • 你的 Dockerfile 的命令很乱。您需要在运行npm install 之前复制package*.json,否则您只是在安装一个空包。不需要npm ci,因为它运行npm install。此外,您还有两个 CMD 语句。这是预期的吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-06
    • 2019-11-26
    • 2018-11-19
    • 2020-07-16
    • 1970-01-01
    • 2018-02-16
    • 2015-02-28
    相关资源
    最近更新 更多