无法通过Docker容器中的apache访问本地网站(windows&docker工具箱)
问题描述:
我使用apache2和一些配置构建了Docker镜像,以便在Windows上运行本地Web服务器。无法通过Docker容器中的apache访问本地网站(windows&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>
在我的/ C /用户/公共/网站/测试文件夹,我只是有一个index.php文件,其中包含以下代码:
<?php
phpinfo();
我使用此命令构建了我的映像泊坞窗快速启动终端
docker build -t php56 .
然后,我建我的容器:
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: '
我的问题是,我可以” t访问我的测试网站,我不知道为什么。
我试图在/etc/apache2/apache2.conf中添加“ServerName 172.17.0.2”指令,但是当我重新启动apache2服务时,它停止运行我的容器。
我想检查我的容器来看看它的IP,但有时它没有一个有时是172.17.0.2
我想在我的浏览器下不会忽略,但我不能达到任何东西:
172.17.0.2:80
0.0.0.0:80
有人知道如何在Windows上使用Docker运行Web服务器,并使用Servername访问网站吗? (test.loc)
答
您需要知道的一点是,当您在Windows上运行Docker时,它并非实际在Windows计算机上运行,但Docker工具箱创建了一个虚拟框VM,以便运行Docker。你可以在这里阅读更多关于https://docs.docker.com/engine/installation/windows/ ,这样你就可以在虚拟机器虚拟机拥有的ip上检查你的网站。 要找出虚拟机的IP地址,你可以使用以下命令:
docker-machine ip
谢谢你的回答!我设法用docker-machine ls获得机器清单,然后用ip到达我的网站。但是,有没有办法只确定一次IP地址以便将其写入虚拟主机? – jiboulex
你不需要虚拟主机的IP地址。本着容器中的“docker way”软件的精神,容器本身应该在每个docker主机上运行。他们应该以任何方式依赖于主机的IP。 – kashian
我的意思是,如果我想通过测试到达我的本地网站。loc ServerName,我需要将机器的IP放在VirtualHost中。我有办法确定自己机器的IP地址是否预先插入到虚拟主机中,并确保它不会更改? – jiboulex