1

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.

stdcerr
  • 13,725
  • 25
  • 71
  • 128
  • 1
    Not long ago I saw this problem and [this](https://stackoverflow.com/questions/60129247/docker-file-permissions-with-volume-bind-mount) was the problem. Does it help? – Silidrone Feb 13 '21 at 18:15
  • No, unfortunately just adding `:Z` behind the path does not seem to work for me, I changed the line to `-v /tmp/docker:/home/vault/tmp:Z` but still is owned by `root` inside the container – stdcerr Feb 13 '21 at 18:34
  • 1
    maybe you want `--user "$(id -u):$(id -g)"` ? – anthony sottile Feb 13 '21 at 18:38
  • I've added that to my `run` command but still no go, I've also updatated the original post on top. – stdcerr Feb 13 '21 at 18:56

2 Answers2

2

Your /tmp folder probably uses tmpfs which behaves differently than for example ext4, especially when it comes to SELinux labeling (with the :Z option).

Try using a folder which lies on an ext4 filesystem.

Michael Dreher
  • 1,369
  • 11
  • 17
0

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.

stdcerr
  • 13,725
  • 25
  • 71
  • 128