npm 错误!追踪器“idealTree"为 Node 项目创建 Docker 映像时已存在 [英] npm ERR! Tracker "idealTree" already exists while creating the Docker image for Node project

查看:59
本文介绍了npm 错误!追踪器“idealTree"为 Node 项目创建 Docker 映像时已存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为 simpleWeb 的 node.js 项目.该项目包含 package.json 和 index.js.

I have created one node.js project called simpleWeb. The project contains package.json and index.js.

index.js

    const express = require('express');
    
    const app = express();
    
    app.get('/', (req, res) => {
      res.send('How are you doing');
    });
    
    app.listen(8080, () => {
      console.log('Listening on port 8080');
    });

package.json

package.json


    {
        "dependencies": {
          "express": "*"
        },
        "scripts": {
          "start": "node index.js"
        }
      }

我还创建了一个 Dockerfile 来为我的 node.js 项目创建 docker 映像.

I have also created one Dockerfile to create the docker image for my node.js project.

Dockerfile

# Specify a base image
FROM node:alpine

# Install some dependencies 
COPY ./ ./
RUN npm install

# Default command
CMD ["npm", "start"]

虽然我尝试使用docker build"来构建 docker 映像.命令它抛出错误.

While I am tried to build the docker image using "docker build ." command it is throwing below error.

错误日志

simpleweb » docker build .                                                    ~/Desktop/jaypal/Docker and Kubernatise/simpleweb
[+] Building 16.9s (8/8) FINISHED
 => [internal] load build definition from Dockerfile                                                                         0.0s
 => => transferring dockerfile: 37B                                                                                          0.0s
 => [internal] load .dockerignore                                                                                            0.0s
 => => transferring context: 2B                                                                                              0.0s
 => [internal] load metadata for docker.io/library/node:alpine                                                               8.7s
 => [auth] library/node:pull token for registry-1.docker.io                                                                  0.0s
 => [internal] load build context                                                                                            0.0s
 => => transferring context: 418B                                                                                            0.0s
 => [1/3] FROM docker.io/library/node:alpine@sha256:5b91260f78485bfd4a1614f1afa9afd59920e4c35047ed1c2b8cde4f239dd79b         0.0s
 => CACHED [2/3] COPY ./ ./                                                                                                  0.0s
 => ERROR [3/3] RUN npm install                                                                                              8.0s
------
 > [3/3] RUN npm install:
#8 7.958 npm ERR! Tracker "idealTree" already exists
#8 7.969
#8 7.970 npm ERR! A complete log of this run can be found in:
#8 7.970 npm ERR!     **/root/.npm/_logs/2020-12-24T16_48_44_443Z-debug.log**
------
executor failed running [/bin/sh -c npm install]: exit code: 1

上面的日志文件提供了一个路径/root/.npm/_logs/2020-12-24T16_48_44_443Z-debug.log"我可以在哪里找到完整的日志.

The log file above it is providing one path "/root/.npm/_logs/2020-12-24T16_48_44_443Z-debug.log" where I can find the full logs.

但是,我的本地机器上不存在上述文件.

But, The above file is not present on my local machine.

我不明白这是什么问题.

I don't understand what is the issue.

推荐答案

这个问题是由于nodejs从15版本开始的变化造成的.当没有指定WORKDIR时,在容器的根目录下执行npm install,即导致此错误.在 WORKDIR 指定的容器的项目目录中执行 npm install 可以解决此问题.

This issue is happening due to changes in nodejs starting version 15. When no WORKDIR is specified, npm install is executed in the root directory of the container, which is resulting in this error. Executing the npm install in a project directory of the container specified by WORKDIR resolves the issue.

使用以下 Dockerfile:

Use the following Dockerfile:

# Specify a base image
FROM node:alpine

#Install some dependencies

WORKDIR /usr/app
COPY ./ /usr/app
RUN npm install

# Set up a default command
CMD [ "npm","start" ]

这篇关于npm 错误!追踪器“idealTree"为 Node 项目创建 Docker 映像时已存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆