Search code examples
dockercentosrhelselinux

Docker container receives permission denied in mounts


On RHEL, CentOS, Fedora, and other SELinux-enabled distributions, creating a docker image with mounts and turned-on SELinux returns permission denied:

docker run --rm -it -v $(pwd):/home centos7
[root@4b348767653c ~]# ls /home
ls: cannot open directory /home: Permission denied

How do I continue using Docker images with mounted volumes without turning off SELinux?


Solution

  • Use special flag :Z to mount your volumes, for example:

    docker run --rm -it -v $(pwd):/home:Z centos7
    [root@4b348767653c ~]# ls /home
    Documents Downloads ...
    

    For more information about SELinux contexts, see thePractical SELinux and Containers blog.