我正在尝试 Dockerize 一个 Vue.js 应用程序。我使用 node:10.15-alpine
Docker 映像作为基础。映像构建失败并出现以下错误:
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack at PythonFinder.failNoPython (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:484:19)
gyp ERR! stack at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:406:16)
gyp ERR! stack at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:68:16)
gyp ERR! stack at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:80:29)
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:89:16
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/isexe/index.js:42:5
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/isexe/mode.js:8:5
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:154:21)
gyp ERR! System Linux 4.9.125-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 /app/node_modules/inotify
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (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 ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! inotify@1.4.2 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the inotify@1.4.2 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
该应用程序在我的 Ubuntu 机器上运行。我已经在网上搜索了解决方案。
我试过了:
FROM node:10.15-alpine
EXPOSE 8080
RUN mkdir -p /app/src
WORKDIR /app
COPY build/ config/ dist/ static/ .babelrc .postcssrc.js index.html /app/
COPY package*.json ./
RUN apk add --no-cache make gcc g++ python && \
npm install --production --silent && \
apk del make gcc g++ python
ADD src/ /app/src/
CMD ["npm", "start"]
这也失败了。错误输出非常冗长,并且引用了 C/C++ 代码。
这是我当前的 Dockerfile:
FROM node:10.15-alpine
EXPOSE 8080
RUN mkdir -p /app/src
WORKDIR /app
COPY build/ config/ dist/ static/ .babelrc .postcssrc.js index.html /app/
COPY package*.json ./
RUN npm install
ADD src/ /app/src/
CMD ["npm", "start"]
谁能帮我用 node-gyp 解决这个问题?我希望能够使用 Docker 容器运行应用程序,但我需要先构建映像。
更新
由于构建在我的 Ubuntu 机器上运行,我检查了 node
版本。它是 8.12,所以我切换到使用 node:8.12-alpine
图像,应用程序现在可以使用以下 Dockerfile:
FROM node:8.12-alpine
RUN apk add g++ make python
EXPOSE 8080
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN npm install
CMD ["npm", "start"]
原文由 Jason 发布,翻译遵循 CC BY-SA 4.0 许可协议
在我的帖子更新中也有说明,这里是
Dockerfile
我曾经让事情正常工作:如果您的要求要求图像最小化空间,请考虑使用
RUN apk add --no-cache --virtual [package-list]
(而不是apk add [package-list]
)安装必要的软件包,然后使用RUN apk del .gyp
6dd682058d3ec75dce4413f458c341 清除图像中的缓存。