How to enable SELinux inside of a CentOS Docker container?

sffc asked:

I am trying to install SELinux inside of a Docker container in order to distribute an application that uses SELinux internally.

The default CentOS image does not have SELinux installed:

$ docker run -it centos:latest /bin/bash
[[email protected] /]# sestatus
bash: sestatus: command not found

After I install it from yum, SELinux is not enabled yet.

[[email protected] /]# yum install policycoreutils selinux-policy-targeted
[[email protected] /]# sestatus
SELinux status:                 disabled

All the documentation I’ve found says that you need to issue a system reboot in order to install it. However, I am not aware of a method to simulate a system reboot inside a Docker container.

How does one go about installing and enabling SELinux inside of a container?

My answer:

SELinux is not namespaced, so individual containers cannot have their own separate SELinux policies. SELinux will always appear to be “disabled” in a container, though it is running on the host.

If your application requires SELinux, you cannot use it inside Docker. You will need to use a regular virtual machine.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.