在构建Docker文件时,我遇到错误执行器运行失败[/bin/sh-c npm install]:退出代码:1

5ktev3wc  于 2023-03-01  发布在  Docker
关注(0)|答案(2)|浏览(758)

我尝试构建节点应用程序的映像,但在执行时显示错误。

PS C:\Users\vallabh\Desktop\visits> docker build .
[+] Building 3.8s (5/5) FINISHED

[internal] load build definition from Dorkerfile
=> transferring Dockerfile! 31B
=> [internal] load .dockerignore
=> => Transferring context: 2B 
=> [internal] load metadata for docker.io/library/node:alpine 
=> CACHED [1/2] FROM docker.io/library/node:alpine@sha256 :0677e437543016F6cb058d92792a14e5eb84348e3d5b4
> ERROR [2/2] RUN npm install:

确切的误差为:

------
 > [2/2] RUN npm install:
#5 1.745 npm ERR! Tracker "idealTree" already exists
#5 1.748
#5 1.748 npm ERR! A complete log of this run can be found in:
#5 1.748 npm ERR! /root/.npm/_logs/2022-05-28T07_47_19_509Z-debug-0.log
------
executor failed running [/bin/sh -c npm install]: exit code: 1
PS C:\Users\vallabh\Desktop\visits> executor failed running [/bin/sh -c npm install]: exit code: 1D

如何避免此npm install错误?
举例说明:

zu0ti5jz

zu0ti5jz1#

首先检查您是否有类似的问题as in here
此问题的发生是由于NodeJS从版本15开始的更改。
如果未指定WORKDIR,则在容器的根目录中执行npm install,从而导致此错误。
WORKDIR指定的容器的项目目录中执行npm install可以解决此问题。
在您的情况下,请确保将WORKDIR设置为您的节点应用程序在您正在构建的映像中驻留的位置。

cpjpxq1n

cpjpxq1n2#

我已经在Dokerfile中包含了节点版本。对我有效

FROM node:19.5.0-alpine

相关问题