Looks like this some people still struggle to find a solution, even with all the above suggestions.
I’ve had a problem with this functionality as well, and after trying a number of fixes suggested here, I’ve discovered another aspect of this, that might help some.
Mounting drivers in Linux is a non-trivial operation and, following my observation, looks that it’s also asynchronous.
In my case, I was testing mounting functionality by issuing:
docker run -it -v "$PWD":/usr/src/app -w /usr/src/app node:8.9-alpine ls -l
But the output was empty, although my host’s working directory wasn’t. I wanted to check that the -w switch (set working directory on guest) works correctly so I’ve changed the command to:
docker run -it -v "$PWD":/usr/src/app -w /usr/src/app node:8.9-alpine pwd & ls -l
which has not only returned the right path, but also listed all the contents of my hosts working directory.
This suggested to my that my previous command failed to list the contents, simply because the drive was not mounted at the point of execution.
After making that observation, I’ve started adding “sleep 1s &” before the main command to pause the execution before the guest OS mounts the drive. This solved all my problems with mounting.
I know it’s not the nicest fix and it feels hacky, but at the end of the day, lets not forget that this command builds a virtual operating system - an operation which is very complex and, as it turns up, rather hard to predict, unless you’re willing to learn the ins-and-outs of the guest OS.