I am building a docker haproxy 1.8 custom image on top of centos 7. I want to open port 80 for the front end but whenever IO start the container, it complains about "cannot bind socket on port 80", however it can bind on 8080 and other which are not is use as usual. I believe it has to do with kernal parameters but I cannot run sysctl in dockerfile which returns "Read-only" file system. docker run has --sysctl commandline but it doesn't have any effect I believe.
my Dockerfile is as follows :
FROM centos:7
MAINTAINER "SAGAR"
ADD ["http://www.haproxy.org/download/1.8/src/haproxy-1.8.20.tar.gz", "/tmp/"]
RUN mkdir /etc/haproxy
COPY ["haproxy.cfg", "/etc/haproxy/"]
RUN yum -y update && \
yum -y install wget tar gcc pcre-static pcre-devel make perl zlib-devel openssl-devel systemd-devel make && \
groupadd -r haproxy && \
useradd -g haproxy -d /etc/haproxy -s /sbin/nologin -c "Haproxy User" haproxy && \
chown -R haproxy:haproxy /etc/haproxy && \
chmod -R 774 /etc/haproxy && \
cd /tmp/ && \
tar -xvzf /tmp/haproxy-1.8.20.tar.gz && \
cd /tmp/haproxy-1.8.20 && \
make TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_CRYPT_H=1 USE_LIBCRYPT=1 USE_LINUX_TPROXY=1 USE_SYSTEMD=1 USE_THREAD=1 && \
make install && \
ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy && \
yum clean all;
EXPOSE 80 443 13888 9000
USER haproxy
CMD ["/usr/sbin/haproxy", "-W", "-f", "/etc/haproxy/haproxy.cfg"]
My docker run command is :
docker run -d --name haproxy --privileged -p 80:80 haproxy:80
Copyright Notice:Content Author:「SAGAR BHOOSHAN」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/57264139/docker-centos7haproxy1-8-on-port-80