Thought I'd just wanted to share this. So I am testing creation of a docker image/container with a nodejs app usiung Dockerfile. Everything went smoothly, until I tried to add the .dockerignore file, where I listed the following files in it, expecting that they won't get copied into the docker image:
node_modules
dockerignore
Dockerfile
And here is my Dockerfile:
FROM node:latest
WORKDIR /app
ADD . .
RUN npm install
CMD node index.js
So I trashed and rebuilt my image with the existing Dockerfile and the new .dockerignore file. After the creation, I ran docker run -it --entrypoint sh <image name> to check if those files/folders do not appear anymore.
Dockerfile and .dockerignore are gone. But node_modules folder is still there.
Took me a while to "realize" that MAYBE the node_modules folder in the image is created by the Dockerfile's npm install step, not the folder copied from the host anyway.
Am I right?