简体   繁体   中英

Docker build (Windows) hangs after RUN 'npm install'

As the title says, I am trying to build a Dockerfile with 'NPM install' as follows:

FROM mcr.microsoft.com/windows/nanoserver:1809 AS build-nodejs
WORKDIR /app
COPY . .

ARG NODE_VERSION=12.10.0

RUN echo "Downloading NodeJS version %NODE_VERSION% ..." && \
    curl "https://nodejs.org/dist/v%NODE_VERSION%/node-v%NODE_VERSION%-win-x64.zip" --output nodejs.zip && \
    echo "Expanding NodeJS ..." && \
    tar -xvf nodejs.zip -C "C:\\" 

RUN SET "PATH=%PATH%C:\node-v%NODE_VERSION%-win-x64" && \
    SET NODE_OPTIONS="--max_old_space_size=4096" && \
    SET CI=true && \
    ECHO "npm install ..." && \
    npm install
 .
 . 
 .

MOVING TO THE FOLLOWING 'FROM' STEP TAKES 15MIN!

FROM mcr.microsoft.com/dotnet/core/sdk:3.0.100 AS build-netcore
WORKDIR /app
.
.
.

What happens between the RUN command and the FROM step?
Why it is taking 15 minutes to move on to the FROM step? I suspect the node_modules creation inside the image to be the cause, probably it gets passed to the FROM section somewhy.
I might be wrong of course and would love to hear more opinions!

So after I have added:

RUN del /S /Q node_modules

After "npm install", leaping between RUN and FROM steps took only 3min and not 15min as it was before.
As I suspected, "node_modules" directory that got created in the RUN's layer delayed the transformation between the layers.
I simply don't understand the process behind what gets passed between layers, if someone could enlight me it will be very helpful.

There are only two chances. FROM will download the image but only first time on the same box.
Your copy. . Will take time if your directly is huge in content.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM