Docker node.js app -volume working with docker managed volume not working when host path is specified

I am running a node.js app in a docker container successfully. The node.js app uses a database (nedb) and the db records are stored in the file database.db in the root dir of the app.

I would like to monitor this file from host system and therefore I would like to use a volume not managed by docker and I would like to specify the host directory using this command

docker run -p 4000:4000 --name websrv -v /home/pi/websrv/db:/app websrv:v1.2

however I get the error
npm ERR! enoent ENOENT: no such file or directory, open ‘/app/package.json’
npm ERR! enoent This is related to npm not being able to find a file.

when I use the volume managed by docker
pi@raspberrypi:~/websrv $ docker run -p 4000:4000 --name websrv -v myvol:/app websrv:v1.2
the application is running without error however I cannot monitor the database file becaues volume is managed by docker

Any idea what’s wrong?

You are using a bind mount, not a volume. The difference is that you mount an empty folder and the content from the container will not be copied to the host folder. The empty host folder will override the folder in the container.

Search for “docker volume custom path” to use a custom path for volumes:

Quote from stackoverflow

docker volume create --name my_test_volume --opt type=none --opt device=/home/jinna/Jinna_Balu/Test_volume --opt o=bind

many thanks - now it works - helped me a lot