Anand Kumar
Anand Kumar

Reputation: 393

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.

Upvotes: 3

Views: 17413

Answers (1)

Afeef Janjua
Afeef Janjua

Reputation: 659

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 . .

Upvotes: 3

Related Questions