Cannot finde module 'express' (node app with docker) Cannot finde module 'express' (node app with docker) express express

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.

  1. Dockerfile

    FROM alpine:latest WORKDIR /usr/src/appCOPY . .

  2. I create a test.t file in the same directory of Dockerfile.

  3. Proving

    1. Run command docker build -t test-1 .
    2. Run command docker run --name test-c-1 -it test-1 /bin/sh,then your container will open bash.
    3. Run command ls -l in your container bash,it will show test.t file.
    4. Just use the same image.
    5. 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.

That's all.I hope it will help you.


I recently faced the similar issue.Upon digging into docker docs I discovered that when you run the command

docker run -p 49160:8080 -v ~/Documentos/nodeApp:/home/Documents/node-app node-cont

the directory on your host machine ( left side of the ':' in the -v option argument ) will be mounted on the target directory ( in the container ) ##/home/Documents/node-app##and since your target directory is working directory and so non-empty, therefore

"the directory’s existing contents are obscured by the bind mount."