It appeared that docker-machine mounted my local
/hosthome by default.
--volume option for
docker run has a difference to
--mount option: local folder is automatically created if it doesn’t exist.
That’s why when calling
docker run -v /home/a/b/c:/xxx, an empty folder was created at path
/home/a/b/c inside virtual machine first, and then mounted to container at path
First takeaway was to stop using
-v option and start using
docker run --mount type=bind,source=/home/a/b/c,target=/xxx. In this case the command will fail fast with error as the source path doesn’t exist in virtual machine.
Second step was to remove default shared folder from the virtual machine (my driver was
virtualbox) and replace it with proper one with matching path. Performing these operations on stopped vm:
docker-machine stop vboxmanage sharedfolder remove default --name hosthome vboxmanage sharedfolder add default --name $HOME --hostpath $HOME --automount docker-machine start