Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you run an Openshift Docker container as something besides root?

I'm currently running Openshift, but I am running into a problem when I try to build/deploy my custom Docker container. The container works properly on my local machine, but once it gets built in openshift and I try to deploy it, I get the error message. I believe the problem is because I am trying to run commands inside of the container as root.

(13)Permission denied: AH00058: Error retrieving pid file /run/httpd/httpd.pid

My Docker file that I am deploying looks like this -

FROM centos:7
MAINTAINER me<me@me>
RUN yum update -y
RUN yum install -y git https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

RUN yum install -y ansible && yum clean all -y
RUN git clone https://github.com/dockerFileBootstrap.git
RUN ansible-playbook "-e edit_url=andrewgarfield edit_alias=emmastone site_url=testing.com" dockerAnsible/dockerFileBootstrap.yml
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
COPY supervisord.conf /usr/etc/supervisord.conf
RUN rm -rf supervisord.conf
VOLUME [ "/sys/fs/cgroup" ]
EXPOSE 80 443
#CMD ["/usr/bin/supervisord"]
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]

Ive run into a similar problem multiple times where it will say things like Permission Denied on file /supervisord.log or something similar.

How can I set it up so that my container doesnt run all of the commands as root? It seems to be causing all of the problems that I am having.

like image 715
J. Doe Avatar asked Jun 09 '16 10:06

J. Doe


People also ask

How do I run as non-root Docker?

To run Rootless Docker inside “rootful” Docker, use the docker:<version>-dind-rootless image instead of docker:<version>-dind . The docker:<version>-dind-rootless image runs as a non-root user (UID 1000).

Does OpenShift run containers as root?

So OpenShift has the responsibility to secure your apps, which is why OpenShift does not allow containers to run as root.

Does Docker have to run as root?

Running the container as root brings a lot of risks. Although being root inside the container is not the same as root on the host machine (some more details here) and you're able to deny a lot of capabilities during container startup, it is still the recommended approach to avoid being root .


1 Answers

Openshift has strictly security policy regarding custom Docker builds.

Have a look a this OpenShift Application Platform

In particular at point 4 into the FAQ section, here quoted.

4. Why doesn't my Docker image run on OpenShift?

Security! Origin runs with the following security policy by default:

Containers run as a non-root unique user that is separate from other system users They cannot access host resources, run privileged, or become root They are given CPU and memory limits defined by the system administrator Any persistent storage they access will be under a unique SELinux label, which prevents others from seeing their content These settings are per project, so containers in different projects cannot see each other by default Regular users can run Docker, source, and custom builds By default, Docker builds can (and often do) run as root. You can control who can create Docker builds through the builds/docker and builds/custom policy resource. Regular users and project admins cannot change their security quotas.

Many Docker containers expect to run as root (and therefore edit all the contents of the filesystem). The Image Author's guide gives recommendations on making your image more secure by default:

Don't run as root

Make directories you want to write to group-writable and owned by group id 0 Set the net-bind capability on your executables if they need to bind to ports <1024

Otherwise, you can see the security documentation for descriptions on how to relax these restrictions.

I hope it helps.

like image 187
Sgrilux Avatar answered Sep 28 '22 02:09

Sgrilux