Most of the Dockerfile you will find on Internet build and run softwares as root ! This must scare everybody, right ? ... but it doesn't seems to be the case ...
So the pb is that running a server as root, even in a container, IS DANGEROUS, because root inside a container is quite the same as root outside the container.
One of the solution is to build a Dockerfile properly by using "USER" instruction like this example for a tor relay.
Another solution is to use the "linux user namespaces" to "map" UID/GID inside container to UID/GID outside a container. for exemple root (uid=0) inside a container can be mapped to your personal user account inside the host, so files created in a shared volume has good permissions.
So my question is :what is the best practice when it comes to security with Docker ? run code as non root (i.e. USER instruction in a Dockerfile) ? Or by using "user namespaces" ? Or eventually (or additionnally) by using selinux and/or AppArmor ?
Thanks :)