However, we need to note that the user "aiguru" is local to the container and, in general, not known to the host system. In order to avoid issues with the files we create inside the container, we need to map the (Linux) user and group ID to the values we have on the host system. We do this with the following parameter:
--user=`id -u`:`id -g`
--user=\`id -u\`:\`id -g\`
However, since the users on the host and docker image typically don't have the same name, we may encounter the situation that the username for this ID does not exist in the docker container. Unless we require this for our application, it is largely a cosmetic problem for interactive use.
The full command to run the docker image with a bind-mount is then:
assuming that we are on the host in the local directory that contains the file PyTorch_MNIST.py that we want to execute. If we do not specify "python bindmount/PyTorch_MNIST.py", we would enter an interactive shell.
...
...
@@ -75,7 +75,7 @@ docker rm $(docker ps -a -f status=exited -q) : remove all exited containers
docker system prune -a : everything
### Run
docker run -it --name NAME --user=`id -u`:`id -g` --mount type=bind,source=SRC_DIR,target=TARGET_DIR TAG SCRIPT
docker run -it --name NAME --user=\`id -u\`:\`id -g\` --mount type=bind,source=SRC_DIR,target=TARGET_DIR TAG SCRIPT