Docker Community Forums

Share and learn in the Docker community.

No root Docker on Ubuntu - accessing a Docker volume created with docker run from the host OS

I’ve created a container and used the volume switch to share a directory between the host and my container, e.g. -v /home/docker/mydirectory:/etc/myapp/directory I can see the directory as root or a sudo user, but my docker daemon is running under the docker user (no sudo privileges) for security reasons, however, that user has no rights to the files in that directory on the host. The owner of the directory is a number (165605):

drwx------ 19 165605 docker mydirectory

As you can see, only the 165605 “user” has access by default.

How do I assign or ensure the user used to run the docker daemon has access when creating the container?

I’m having another go at re-wording this after some research.
Basically, the way I understand it, one of the purposes of volumes (apart from persisting data after the container is destroyed) is to be able to access (and back up or modify) container data from the host OS.
Now when running the container as a non-sudo user (no root mode), I can create the volume, inspect and access it using the same user that I configured Docker under (user name=docker, group=docker), but when I deploy a container and use the -v option to connect my volume to an existing directory in my container, I have no access to the data in the volume. Rights for the volume directory (created under /home/docker/.local/share/docker/volumes) are as follows:

drwx-----x 3 docker docker 4096 Oct 14 10:33 test

…but to the files within my test volume:

drwx------ 19 165605 165605 4096 Oct 14 11:50 _data

My docker user has no access at that point, only ‘165605’.
I can ssh in as a sudo user and access the contents fine. How do I enable access to my docker user to the test volume from the host OS when using no-root mode?