Home > Software design >  Excluding a directory via dockerfile in nodejs app
Excluding a directory via dockerfile in nodejs app

Time:10-27

I have a nodejs app and I did containerized it with docker. Here is my dockerfile :

FROM node:14.17.0-alpine
WORKDIR /nodejs
COPY src/* .
COPY app.js .
COPY package*.json /nodejs/
COPY . .
RUN npm install

CMD [ "node", "app.js" ]

As you can see I am copying everything, but I want to exclude node_modules folder. What should I add to the dockerfile in order to tell to to igonore that dir?

UPDATE As mentioned in the comments, I need the .ignorefile to exclude the node_module forlder.I have already used this line :

**/node_modules

in .dockerignore but did not work.

my folder structure :

https://i.stack.imgur.com/A17PA.png

CodePudding user response:

that's the purpose of the .dockerignore file, you can either create one or copy specific folders by name or directory.

UPDATE:

After getting more information it is clear that the path to the folder to be ignored is misplaced,

replace

**/node_modules

with

node_modules

or

./node_modules*
  • Related