Php Can';t在docker容器(windows&;docker工具箱)中通过apache访问本地网站

Php Can';t在docker容器(windows&;docker工具箱)中通过apache访问本地网站,php,windows,apache,docker,dockerfile,Php,Windows,Apache,Docker,Dockerfile,为了在windows上运行本地web服务器,我使用apache2和一些配置构建了一个Docker映像 以下是Dockerfile: FROM php:5.6.15-apache RUN apt-get update && apt-get install -y \ apt-utils vim git php5-mysql php5-memcache php5-memcached php5-intl \ sendmail aptitude wget RUN apt-get inst

为了在windows上运行本地web服务器,我使用apache2和一些配置构建了一个Docker映像

以下是Dockerfile:

FROM php:5.6.15-apache

RUN apt-get update && apt-get install -y \
apt-utils vim git php5-mysql php5-memcache php5-memcached php5-intl \
sendmail aptitude wget
RUN apt-get install libapache2-mod-php5 -y -o Dpkg::Options::="--force-confdef"
RUN docker-php-ext-install mbstring
RUN docker-php-ext-install pdo pdo_mysql
RUN apt-get install libcurl4-gnutls-dev -y
RUN docker-php-ext-install curl
RUN apt-get update && apt-get install -y zlib1g-dev libicu-dev g++
RUN docker-php-ext-configure intl
RUN docker-php-ext-install intl

RUN a2enmod rewrite

ENV APACHE_RUN_USER test
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

EXPOSE 80

COPY php.ini /usr/local/etc/php/php.ini

COPY apache-config.conf /etc/apache2/sites-enabled/000-default.conf
在apache-config.conf中,我只有一个小虚拟主机:

<VirtualHost *:80>
  ServerName test.loc
  DocumentRoot /var/www/html/test

  <Directory /var/www/html/test/>
      Allow from all
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
然后我构建了我的容器:

docker run --name=php56_container -t --rm -v "//c/Users/Public/sites:/var/www/html" -p 80:80 -p 8080:8080 php56
容器创建得很好,但我收到以下消息:

AH00558: apache2: 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
AH00558: apache2: 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
[Mon Dec 21 14:18:24.968215 2015] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) configured -- resuming normal operations
[Mon Dec 21 14:18:24.968982 2015] [core:notice] [pid 1] AH00094: Command line: '
我的问题是我无法访问我的考试网站,我不知道为什么。

我试图在/etc/apache2/apache2.conf中添加“ServerName 172.17.0.2”指令,但当我重新启动apache2服务时,它会停止容器的运行

我试图检查我的容器以查看其ip,但有时它没有ip,有时它是172.17.0.2

我在浏览器中尝试了以下地址,但什么都找不到:

172.17.0.2:80

0.0.0.0:80


有人知道如何在windows上使用Docker运行Web服务器并使用他的服务器名访问站点吗?(test.loc)

您需要知道的是,当您在windows上运行docker时,它并不是在您的windows计算机上实际运行,但docker toolbox会在其中创建一个虚拟箱VM来运行docker。你可以在这里读到更多 因此,您可以在虚拟机拥有的ip上查看您的网站。 要查找vm的ip地址,可以使用以下命令

docker-machine ip

在Dockerfile上添加此行

RUN echo "ServerName www.example.com" >> /etc/apache2/apache2.conf

谢谢你的回答!我设法用docker machine ls获取机器列表,然后用ip访问我的网站。但是,有没有一种方法可以只确定一次ip地址,以便将其写入虚拟主机?虚拟主机中不需要ip地址。本着“docker方式”的精神,容器中的软件和容器本身应该在每个docker主机上运行。它们应该以任何方式依赖于主机的ip。我的意思是,如果我想使用test.loc ServerName访问我的本地网站,我需要将机器的ip放入虚拟主机。我是否有办法自己确定机器的ip,以将其预插入虚拟主机并确保其不会更改?为此,您可以为virtaulbox分配一个静态ip,并编辑主机文件以将该ip映射到测试/定位我发现虚拟箱网络有时很棘手,我不知道docker工具箱会如何反应。有关ssh进入虚拟机的更多信息,请参阅本页底部,并在(大多数)linux操作系统中设置联网
docker-machine ip
RUN echo "ServerName www.example.com" >> /etc/apache2/apache2.conf