Using docker for Development (confused)

I’m trying to set up Docker for development using NodeJS, I noticed that it doesn’t matter if I copy the package.json or anything in the Dockerfile to generate the image and after that the container if I mount the same directory as volume (cause I need to have the changes in real time in the container and the host), and so I was wondering: if it doesn’t matter to create a Dockerfile for that case, is it okay to use only the image node:11.3.0-alpine for example directly in the docker-compose.yml instead of creating a Dockerfile?
The reason I’m asking this is cause as I said, it doesn’t matter if I create a Dockerfile copying the package.json, then executing RUN npm install and so on as the volume will replace everything, and also, something else I noticed: if in my container I run RUN npm install it would generate the node_modules folder, if I mount the volume for that folder and mine and in the host I don’t have a node_modules in the FS it will delete from the container, so I have to install node_modules in my computer as well, it’s REALLY confusing (mostly because I’m on Windows and the container is running Alpine, what would happen with a module that needs to be compiled?)
I really wanted to understand the reason to create a Dockerfile, copy things in development while you need to mount a volume, if it’s needed or I’m doing things wrong.
Thank you guys in advanced :hearts: