CASE 1:
I am trying to mount a host folder dir1 to /dir1 inside docker
docker run --rm -it \
-v "$(pwd)/dir1":"/dir1" \
some_image /bin/bash
I see the permissions inside docker as
drwxr-xr-x 3 hostuser users 4096 Apr 18 13:51 dir1
CASE 2:
Where as if i try to mount a nested folder, i see the parent folders are created with root user and the only the last directory has the host user permission
docker run --rm -it \
-v "$(pwd)/dir1/dir2":"/dir1/dir2" \
some_image /bin/bash
here i see /dir1 permission inside docker as
drwxr-xr-x 3 root root 4096 Apr 18 13:51 dir1
and
here i see /dir1/dir2 permission inside docker as
drwxr-xr-x 3 hostuser users 4096 Apr 18 13:51 dir2
I am expecting both the dir1 and dir2 to have hostuser users permissions
How can i achieve this
SOLUTION
docker run --rm -it \
-v "$(pwd)/dir1":"/dir1" \
-v "$(pwd)/dir1/dir2":"/dir1/dir2" \
someimage /bin/bash
I have to mount the parent folder also then i can see its permission as hostusers