Mat*_*ski 6 docker npm-install
我看到了我认为奇怪的 docker 构建问题。它似乎非常适合我的电脑,因为我已经在其他机器上正确地看到了这个构建。看起来 a在执行命令期间docker build失败了。我本来希望构建能够顺利完成。如果出现任何问题,我希望它们在不同的机器上保持一致 - 毕竟这是一个 docker 构建。还值得注意的是,它曾经在我的电脑上正常工作,直到最近才出现故障。我不确定发生了什么变化。我认为最近几天我没有做任何与 docker 相关的重大更改。npm ERR! sh: 1: node-pre-gyp: Text file busynpm install
我正在寻找有关如何解决此问题的任何建议。几天后我可能会重新安装 docker。不管怎样,我认为这是一个有趣的问题,也许在这里讨论它会对其他人有所帮助。
下面是一个最小的设置,在我的电脑上失败,但在其他电脑上有效。
package.json:
{
"name": "test",
"version": "0.1.0",
"author": "test",
"type": "commonjs",
"license": "ISC",
"dependencies": {
"canvas": "^2.11.2"
}
}
Run Code Online (Sandbox Code Playgroud)
Dockerfile:
FROM node:slim
WORKDIR /app
COPY ./package.json ./
RUN npm install
Run Code Online (Sandbox Code Playgroud)
运行docker build --pull --no-cache .失败
[+] Building 3.3s (8/8) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 107B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:slim 0.1s
=> [1/4] FROM docker.io/library/node:slim@sha256:bffbb1bf1a3afd6fbdd822bda7f1e7cb07eb407f3dc 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 201B 0.0s
=> CACHED [2/4] WORKDIR /app 0.0s
=> [3/4] COPY ./package.json ./ 0.0s
=> ERROR [4/4] RUN npm install 3.1s
------
> [4/4] RUN npm install:
#0 3.026 npm notice
#0 3.026 npm notice New minor version of npm available! 9.6.7 -> 9.7.1
#0 3.026 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.7.1>
#0 3.026 npm notice Run `npm install -g npm@9.7.1` to update!
#0 3.026 npm notice
#0 3.027 npm ERR! code 126
#0 3.027 npm ERR! path /app/node_modules/canvas
#0 3.028 npm ERR! command failed
#0 3.028 npm ERR! command sh -c node-pre-gyp install --fallback-to-build --update-binary
#0 3.028 npm ERR! sh: 1: node-pre-gyp: Text file busy
#0 3.029
#0 3.029 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-06-19T16_22_22_524Z-debug-0.log
------
Dockerfile:6
--------------------
4 |
5 | COPY ./package.json ./
6 | >>> RUN npm install
7 |
--------------------
ERROR: failed to solve: process "/bin/sh -c npm install" did not complete successfully: exit code: 126
Run Code Online (Sandbox Code Playgroud)
在此示例中,我使用的是一个canvas包。我发现这也会引起问题,例如软件包@ory/cli。该问题似乎出现在安装过程中运行一些额外脚本的 NPM 软件包中。目前,我不确定这是 Docker 问题还是 NPM 问题。
https://github.com/moby/moby/issues/9547中有一些讨论,但这里提出的解决方案(睡眠/同步和将存储驱动器更改为overlay2)都是不可能的。我无法注入睡眠,因为问题发生在npm install命令期间,并且我无法更改为,overlay2因为......我已经在使用overlay2.
在“dockerfile”文本文件 busy中有一些讨论,建议作者修改他们构建的文件并注入睡眠。就我而言,在使用第 3 方 NPM 包时会发生这种情况,而该包在其他情况下似乎工作正常,因此我无法修改该代码。我也无法注入睡眠,因为失败发生在npm install命令期间。
输出docker info
Client: Docker Engine - Community
Version: 24.0.0
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.10.4
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.17.3
Path: /usr/libexec/docker/cli-plugins/docker-compose
scan: Docker Scan (Docker Inc.)
Version: v0.23.0
Path: /usr/libexec/docker/cli-plugins/docker-scan
Server:
Containers: 8
Running: 2
Paused: 0
Stopped: 6
Images: 8
Server Version: 24.0.0
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 3dce8eb055cbb6872793272b4f20ed16117344f8
runc version: v1.1.7-0-g860f061
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 5.15.0-43-generic
Operating System: Ubuntu 22.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 20
Total Memory: 15.3GiB
Name: mateusz-mcss
ID: FLNN:HZMZ:5PZG:VHGO:2BCN:6MKS:5C4I:DJQT:DT5J:CIGG:QGFD:UYRS
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2154 次 |
| 最近记录: |