I am trying to build a centos docker container with PHP5.6 & Apache2.4. I have created a DockerFile like this -
FROM centos:latest
MAINTAINER Rituparna
RUN yum -y groupinstall 'Basic Web Server'
RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
RUN yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
RUN yum-config-manager --enable remi-php56
RUN yum -y install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
COPY phpinfo.php /var/www/html/
CMD [“/usr/sbin/httpd”, “-D”, “FOREGROUND”]
EXPOSE 80
Then I trigger the following command -
#docker build /docker/ -t webserver:v1
Docker builder successfully. I checked docker images -
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
webserver v1 7653a3ca22df About an hour ago 1.55 GB
docker.io/httpd 2.4 e77c77f17b46 2 weeks ago 140 MB
docker.io/centos latest 9f38484d220f 3 months ago 202 MB
Once docker built successful, I ran the docker like this -
# docker run webserver:v1 cat /etc/issue
\S
Kernel on an \m
Then I run the docker with the following command -
# docker run -d -it -p 8080:80 webserver:v1
c4c4e986ef67e1359d0a9c9c99cadb7ad340717c528da24666e36ea8ad1e3643
I can able to SSH to Docker container like this -
# docker run -it webserver:v1 bash
[root@98c0b59164e3 /]# cd /var/www/html/
[root@98c0b59164e3 html]# ls
phpinfo.php
[root@98c0b59164e3 html]# php -v
PHP 5.6.40 (cli) (built: May 28 2019 10:47:03)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
[root@98c0b59164e3 html]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Apr 24 2019 13:45:48
Now while trying to access the docker hosting like this -
# links http://192.168.0.10:8080/phpinfo.php
It is throwing "Unable to connect". 192.168.0.10 is the IP of HOST SYSTEM. I have also tried to run below command on docker container -
# /usr/sbin/httpd -D 'FOREGROUND'
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
still not able to browse the website from the host system or from LAN.
Need some help to identify and fix the issue.
UPDATE : I managed to run docker by adding a Dockerfile with following -
EXPOSE 80
CMD ["-D", "FOREGROUND"]
ENTRYPOINT ["/usr/sbin/httpd"]
Try adding —-network host
to your docker run
statement. Example from Docker Docs