Search code examples
dockerpermissionsmount

Docker Why are permissions wrong after bind mount?


I'm mounting my hosts /tmp/docker to /home/vault/tmp/ in my container but the user vault in my container does not have write permissions even though on my host, /tmp/docker is set to 777 and the uid and gid values are set to the same in the host & the container too. How can I fix this and make sure that my user vault has write/owner permissions?

HOST

$ ls -la /tmp/docker/
total 8
drwxrwxrwx  2 ron  ron  4096 Feb  5 19:34 .
drwxrwxrwt 12 root root 4096 Feb 13 09:49 ..
ron@ENGDEV:~/novax-prs/docker$ id -u; id -g
1003
1003

GUEST

$ ls -la /home/vault/tmp/
total 8
drwxr-xr-x 2 root  root  4096 Feb 13 06:47 .
drwxr-xr-x 1 vault vault 4096 Feb 13 18:06 ..
vault@novax_prs_build:~$ id -u; id -g
1003
1003

bind mount

docker run -it \
           -e LOCAL_USER_ID=`id -u` \
           --user "$(id -u):$(id -g)" \
           -v ${dir}:/home/vault/ccimx6ulstarter \
           -v /tmp/docker:/home/vault/tmp:Z \
           ${name}

funny enough, the /home/vault/ccimx6ulstarter/ directory has user the permissions set correctly in the container.


Solution

  • created a ~/tmp_docker/ in the host user's home directory and bind mounted that with -v, got the correct permissions in the container and will use this and can use this as ~/tmp/ in my container!

    Saying this, I'm not sure why my host's /tmp/docker/ would not bind with the correct permissions.