Allowing writes to volumes mounted from the host with SELinux ON
As we saw in the earlier recipe when SELinux is configured, a non-privileged container cannot access files on the volume created after mounting the directory from the host system. However, sometimes it is needed to allow access to host files from the container. In this recipe, we'll see how to allow access in such cases.
Getting ready
You'll require a Fedora/RHEL/CentOS host with the latest version of Docker installed, which can be accessed through a Docker client. Also, the SELinux should be set to enforcing, and the Docker daemon configured to use SELinux.
How to do it...
Mount the volume with the z
or Z
option, as follows:
$ docker container run -it -v /tmp:/tmp/host:z alpine ash
$ docker container run -it -v /tmp:/tmp/host:Z alpine ash

How it works…
While mounting the volume, Docker will relabel the volume to allow access.
Note
The z
option tells Docker that the volume content will be shared between containers. Docker will label...