I am trying to run the NVIDIA PyTorch container nvcr.io/nvidia/pytorch:22.01-py3
on a Linux system, and I need to mount a directory of the host system (that I have R/W access to) in the container. I know that I need to use bind mounts, and here’s what I’m trying:
I’m in a directory /home/<user>/test
, which has the directory dir-to-mount
. (The <user> account is mine).
docker run -it -v $(pwd)/dir-to-mount:/workspace/target nvcr.io/nvidia/pytorch:22.01-py3
Here’s the error output:
docker: Error response from daemon: error while creating mount source path '/home/<user>/test/dir-to-mount': mkdir /home/<user>/test: permission denied.
ERRO[0000] error waiting for container: context canceled
As far as I know, docker will only need to create the directory to be mounted if it doesn’t exist already. Docker docs:
The file or directory does not need to exist on the Docker host already. It is created on demand if it does not yet exist.
I suspected that maybe the docker process does not have access; I tried chmod 777
with dir-to-mount
as well as with test
, but that made no difference.
So what’s going wrong?
[Edit 1]
I am able to mount my user’s entire home directory with the same command, but cannot mount other directories inside the home directory.
[Edit 2]
Here are the permissions:
- home directory:
drwx------
test
:drwxrwxrwx
dir-to-mount
:drwxrwxrwx
2
Answers
It appears that I can mount my home directory as a home directory (inside of
/home/<username>
), and this just works.I don't know why the
/home/<username>
path is special, I've tried looking through the docs but I could not find anything relevant.Run the command with sudo as:
sudo docker run -it -v $(pwd)/dir-to-mount:/workspace/target nvcr.io/nvidia/pytorch:22.01-py3