简体   繁体   中英

Copy node_modules into the docker container from outside

Can we copy the mode_modules from outside and paste it in the docker environment and use this for building the application (ng build --prod), so that we can avoid npm install step in docker file.

Ideally, I don't want to use the npm install step in docker file instead want to use the existing node_modeule packages created outside.

What I know docker images are created from base images which provide a working environment, is it possible to copy and paste from node_modules from outside to docker working environment.

Ideally you should not be copying node_modules directory into the container. But if you absolutely need to do so then here is how to do it

Create a dockerfile and extend from your base image

FROM <your_base_nodejs_image>

Optionally, set a working directory inside the container

WORKDIR /app

Then assuming dockerfile is in the same directory as node_modules, you can do this

COPY ./node_modules ./node_modules

Alternatively, If you want to copy all of code in current directory into the container image, do this

COPY . .

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