无法在centos docker容器上运行Webserver

时间:2019-06-28 08:52:30

标签: php apache docker

我正在尝试使用PHP5.6和Apache2.4构建一个centos docker容器。我已经创建了这样的DockerFile-

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

然后我触发以下命令-

#docker build /docker/ -t webserver:v1

Docker构建器成功。我检查了docker图片-

# 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

一旦docker构建成功,我就这样运行docker-

 # docker run webserver:v1 cat /etc/issue
\S
Kernel \r on an \m

然后我使用以下命令运行docker-

# docker run -d -it -p 8080:80 webserver:v1
c4c4e986ef67e1359d0a9c9c99cadb7ad340717c528da24666e36ea8ad1e3643

我可以像这样SSH到Docker容器-

# 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

现在,当尝试像这样访问Docker主机时-

# links http://192.168.0.10:8080/phpinfo.php

它抛出“无法连接”。 192.168.0.10是主机系统的IP。我也试图在docker容器上的命令下面运行-

# /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

仍然无法从主机系统或LAN浏览网站。

需要一些帮助来识别和解决问题。

更新: 我设法通过添加以下Dockerfile来运行Docker -

EXPOSE 80
CMD ["-D", "FOREGROUND"]
ENTRYPOINT ["/usr/sbin/httpd"]

1 个答案:

答案 0 :(得分:0)

尝试将—-network host添加到您的docker run语句中。 Example from Docker Docs