Cannot finde module 'express' (node app with docker)
When you run your container with -v flag, which mean mount a directory from your Docker engine’s host into a container, will overwrite what you do in /home/Documents/node-app,such as npm install.
So you cannot see the node_modules directory in the container.
$ docker run -d -P --name web -v /src/webapp:/webapp training/webapp python app.py
This command mounts the host directory, /src/webapp, into the container at /webapp. If the path /webapp already exists inside the container’s image, the /src/webapp mount overlays but does not remove the pre-existing content. Once the mount is removed, the content is accessible again. This is consistent with the expected behavior of the mount command.
mount a host directory as a data volume.As what the docs said,the pre-existing content of host directory will not be removed, but no information about what's going on the exist directory of the container.
There is a example to support my opinion.
Dockerfile
FROM alpine:latest WORKDIR /usr/src/app COPY . .
I create a test.t file in the same directory of Dockerfile.
Proving
- Run command
docker build -t test-1 .
- Run command
docker run --name test-c-1 -it test-1 /bin/sh
,then your container will open bash. - Run command
ls -l
in your container bash,it will show test.t file. - Just use the same image.
- Run command
docker run --name test-c-2 -v /home:/usr/src/app -it test-1 /bin/sh
. You cannot find the file test.t in your test-c-2 container.
- Run command
That's all.I hope it will help you.