educative.io

Educative

Docker bind mount

I saw bind mount was being used instead of volume mount by using the option -v ./:/home/node/app in the docker run command. But there is a problem here when we deploy the application directly in the container without building it first on the host(which means there is no node_modules directory present on the host right now). When the container starts, all files and folders in the host directory are going to be mapped to the container directory and since node_modules is not present on host, the bind mount mapping of host to container will delete the node_modules directory in container as well resulting in node server not finding any module which is used in the application codebase and the server will crash.
My question is how to deal with it in the development environment using bind mount?