Missing documented feature for "docker run -v /app/node_modules" which does not specify source dir?

I have been watching a tutorial video, and in my case I mount a local dir like so:

docker run -it --rm --name videodownloaderweb --env-file env.list -v /mnt/share:/data

And this lets me mount /mnt/share (which is a virt-manager shared folder from vm host) to /data within the container. The Docker documentation outlines this use case clearly at: docker run | Docker Docs

But, whilst watching this tutorial, the Youtuber gave a second use case which is undocumented as far as I can see? My command is now:

docker run -it --rm --name videodownloaderweb --env-file env.list -v /mnt/share:/data -v "$(pwd):/app" -v /app/node_modules --user 1000:1000 -p 3000:3000 videodownloaderweb /bin/sh

-v “$(pwd):/app” lets me mount my local node.js development files and static files directly over the /app directory within the container. The issue also addressed here is that we don’t want to mount the host ./node_modules directory within the container as these files are specific to the host and no where else. So what is needed is to use the container created “node_modules” in place inside the container. This is achieved in the above command line with: “-v /app/node_modules”. Note that this mount spec is missing a colon, and the source and only references the dest container folder which exists already in the docker image (created during image build). What this does is just use the existing container folder and doesn’t attempt to mount any host directory over it. It’s almost like an exclude/ignore option. Don’t believe this is an anonymous volume?

Can someone explain what this is called and where it is documented on the documentation?

  • In the case of named volumes, the first field is the name of the volume, and is unique on a given host machine. For anonymous volumes, the first field is omitted.

But I never use anonymous volumes. Those can fill up your disk and you will not even know what that volume was for unless it is mounted to a container at the moment.

Ok thanks for clearing that up for me.

The feature for “docker run -v /app/node_modules” without specifying a source directory is missing from the documentation.

See the quote from the docs above.