
Let's say the following error is being returned when using the docker run command to create and start a container.
mkdir: cannot create directory '/foo': Permission denied
This typically occurs when using the docker run command to create and start a container with the -v or --volume option and means that the user that is attempting to create the /foo directory in the container does not have permission to the /usr/local/docker/foo directory on the Docker system.
docker run --volume /usr/local/docker/foo:/foo hello-world
By default, directories on a Linux system will have 0775 or drwxrwxr-x permssion and will be owned by the user that created the directory. In this example, root has read/write/execute permission, and every other user has read and execute, but not write permission.
[root@lab1 ~]# ls -ld /usr/local/docker/foo
drwxr-xr-x 2 root root 6 Sep 27 02:40 /usr/local/docker/foo
One option is to update the directory on the Docker system to have 0777 or drwxrwxrwx permssion, so that all users have read/write/execute permission.
chmod 0777 /usr/local/docker/foo
Another option, and typically the preferred option, is to determine the user that is attempting to create the /foo directory in the container. Let's say the user is john.doe. In this example, you would create the john.doe user on the Docker system.
useradd john.doe
And then update the /usr/local/docker/foo directory on the Docker system to be owned by john.doe.
chown john.doe /usr/local/docker/foo
chgrp john.doe /usr/local/docker/foo
Did you find this article helpful?
If so, consider buying me a coffee over at