Docker Community Forums

Share and learn in the Docker community.

Run httpd as non-root

I have been attempting to get a httpd container running as non-root and I can build the container but it will not start I do need to be running on port 80 to run the webserver. Any one who has tackled this iss please give me an Idea how you did it. Below is my Dockerfile

FROM centos

RUN yum -y update &&
yum -y install httpd &&
yum clean all &&
bash -c ‘echo “This mcoe webserver works!” >> /var/www/html/index.html’

ENV LC_ALL en_US.UTF-8
ENV LANG=en_US.UTF-8

COPY --chown=apache:apache httpd.conf /etc/httpd/conf/

RUN setcap ‘cap_net_bind_service=+ep’ /usr/sbin/httpd
RUN getcap /usr/sbin/httpd

HEALTHCHECK --interval=60s --timeout=30s CMD nc-zv http://localhost:80 || exit 1

USER apache

EXPOSE 80

ENTRYPOINT ["/usr/sbin/httpd"]
CMD ["-D ", “FOREGROUND”]

Thanks all