我正在构建 NextJS 13 应用程序。我通常在 Windows 上工作,但出门在外时我使用的是 Mac。在 Windows 上一切正常,但是当我在我的 Mac 上构建图像时,一切都崩溃了(顺便说一句,芯片 M1)。
这是我的dockerfile:
FROM node:16-alpine
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD npm run dev
这个 dockerfile 在 Mac 上的
RUN npm install
步骤崩溃并抛出大量错误
=> [internal] load build definition from .dockerfile-dev 0.0s
=> => transferring dockerfile: 179B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/node:16-alpine 1.3s
=> [1/5] FROM docker.io/library/node:16-alpine@sha256:029a85552a270cd6dfae 0.0s
=> => resolve docker.io/library/node:16-alpine@sha256:029a85552a270cd6dfae 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 1.69kB 0.0s
=> CACHED [2/5] WORKDIR /app 0.0s
=> [3/5] COPY package*.json . 0.0s
=> ERROR [4/5] RUN npm install 10.0s
------
> [4/5] RUN npm install:
#8 9.721 npm notice
#8 9.722 npm notice New major version of npm available! 8.19.3 -> 9.5.0
#8 9.722 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.5.0>
#8 9.722 npm notice Run `npm install -g [email protected]` to update!
#8 9.722 npm notice
#8 9.723 npm ERR! code 1
#8 9.724 npm ERR! path /app/node_modules/bufferutil
#8 9.725 npm ERR! command failed
#8 9.725 npm ERR! command sh -c -- node-gyp-build
#8 9.725 npm ERR! gyp info it worked if it ends with ok
#8 9.725 npm ERR! gyp info using [email protected]
#8 9.725 npm ERR! gyp info using [email protected] | linux | arm64
#8 9.725 npm ERR! gyp ERR! find Python
#8 9.725 npm ERR! gyp ERR! find Python Python is not set from command line or npm configuration
#8 9.725 npm ERR! gyp ERR! find Python Python is not set from environment variable PYTHON
#8 9.725 npm ERR! gyp ERR! find Python checking if "python3" can be used
#8 9.725 npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error
#8 9.725 npm ERR! gyp ERR! find Python checking if "python" can be used
#8 9.725 npm ERR! gyp ERR! find Python - "python" is not in PATH or produced an error
#8 9.725 npm ERR! gyp ERR! find Python
#8 9.726 npm ERR! gyp ERR! find Python **********************************************************
#8 9.726 npm ERR! gyp ERR! find Python You need to install the latest version of Python.
#8 9.726 npm ERR! gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
#8 9.726 npm ERR! gyp ERR! find Python you can try one of the following options:
#8 9.726 npm ERR! gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
#8 9.726 npm ERR! gyp ERR! find Python (accepted by both node-gyp and npm)
#8 9.726 npm ERR! gyp ERR! find Python - Set the environment variable PYTHON
#8 9.726 npm ERR! gyp ERR! find Python - Set the npm configuration variable python:
#8 9.726 npm ERR! gyp ERR! find Python npm config set python "/path/to/pythonexecutable"
#8 9.726 npm ERR! gyp ERR! find Python For more information consult the documentation at:
#8 9.726 npm ERR! gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
#8 9.726 npm ERR! gyp ERR! find Python **********************************************************
#8 9.726 npm ERR! gyp ERR! find Python
#8 9.726 npm ERR! gyp ERR! configure error
#8 9.726 npm ERR! gyp ERR! stack Error: Could not find any Python installation to use
#8 9.726 npm ERR! gyp ERR! stack at PythonFinder.fail (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:330:47)
#8 9.726 npm ERR! gyp ERR! stack at PythonFinder.runChecks (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:159:21)
#8 9.727 npm ERR! gyp ERR! stack at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:202:16)
#8 9.727 npm ERR! gyp ERR! stack at PythonFinder.execFileCallback (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:294:16)
#8 9.727 npm ERR! gyp ERR! stack at exithandler (node:child_process:410:5)
#8 9.727 npm ERR! gyp ERR! stack at ChildProcess.errorhandler (node:child_process:422:5)
#8 9.727 npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:513:28)
#8 9.727 npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
#8 9.727 npm ERR! gyp ERR! stack at onErrorNT (node:internal/child_process:485:16)
#8 9.727 npm ERR! gyp ERR! stack at processTicksAndRejections (node:internal/process/task_queues:83:21)
#8 9.727 npm ERR! gyp ERR! System Linux 5.15.49-linuxkit
#8 9.727 npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
#8 9.727 npm ERR! gyp ERR! cwd /app/node_modules/bufferutil
#8 9.727 npm ERR! gyp ERR! node -v v16.19.1
#8 9.727 npm ERR! gyp ERR! node-gyp -v v9.1.0
#8 9.727 npm ERR! gyp ERR! not ok
#8 9.729
#8 9.729 npm ERR! A complete log of this run can be found in:
#8 9.729 npm ERR! /root/.npm/_logs/2023-02-22T02_35_48_229Z-debug-0.log
------
executor failed running [/bin/sh -c npm install]: exit code: 1
希望对此有任何见解,我不知道为什么会这样
我能够通过简单地停止忽略
node_modules
并删除一些步骤来解决这个问题,但仍然不知道为什么容器不能正确执行RUN npm install
。
现在的 Dockerfile:
FROM node:16-alpine
WORKDIR /app
COPY . .
EXPOSE 3000
CMD npm run dev
也能够从浏览器访问该页面。如果有人对执行步骤
RUN npm install
或我可以改进 Dockerfile 的任何方式有任何想法,请发布答案。
#8 9.725 npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error
#8 9.725 npm ERR! gyp ERR! find Python - "python" is not in PATH or produced an error
#8 9.726 npm ERR! gyp ERR! find Python You need to install the latest version of Python.
npm 抱怨它找不到安装在你的 mac 上的 python。