duankeye2342 2019-06-28 08:52
浏览 185

无法在centos docker容器上运行webserver

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"]
  • 写回答

1条回答 默认 最新

  • duadlkc5762218 2019-06-28 21:37
    关注

    Try adding —-network host to your docker run statement. Example from Docker Docs

    评论

报告相同问题?

悬赏问题

  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑