Jas*_*son 5 node.js npm node-gyp docker alpine-linux
我正在尝试对Vue.js应用程序进行Docker化。我正在使用node:10.15-alpineDocker映像作为基础。映像生成失败,并出现以下错误:
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.
Run Code Online (Sandbox Code Playgroud)
该应用程序在我的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"]
Run Code Online (Sandbox Code Playgroud)
这也失败了。错误输出非常冗长,并且引用了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"]
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我使用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"]
Run Code Online (Sandbox Code Playgroud)
Jas*_*son 21
在我的帖子更新中也说明了,这是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"]
Run Code Online (Sandbox Code Playgroud)
MGL*_*don 11
由于您在 docker 上使用的是 Alpine 版本,因此您可能希望在修复node-gyp rebuild错误的同时使用尽可能少的空间。为此,建议使用以下命令,即不使用缓存并使用稍后可以删除的虚拟包。您还应该将apk add和npm install命令组合在一起;这将有助于进一步减少 docker 缓存层之间的空间。
FROM node:8.12-alpine
EXPOSE 8080
WORKDIR /app
COPY . .
RUN apk add --no-cache --virtual .gyp \
python \
make \
g++ \
&& npm install \
&& apk del .gyp
CMD ["npm", "start"]
Run Code Online (Sandbox Code Playgroud)
对于任何使用node:16.13-alpine3.15(或关闭版本)的人:
FROM node:16.13-alpine3.15
RUN apk --no-cache add --virtual .builds-deps build-base python3
WORKDIR /app
COPY package*.json ./
RUN npm install --production && npm rebuild bcrypt --build-from-source && npm cache clean --force
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2546 次 |
| 最近记录: |