Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

dockerfile - npm ERR! Tracker "idealTree" already exists while creating the Docker image for Node project

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


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

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"]

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

Error Logs

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

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.

question from:https://stackoverflow.com/questions/57534295/npm-err-tracker-idealtree-already-exists-while-creating-the-docker-image-for

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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" ]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...