我使用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)
謝謝你的回答!我設法用docker-machine ls獲得機器清單,然後用ip到達我的網站。但是,有沒有辦法只確定一次IP地址以便將其寫入虛擬主機? – jiboulex
你不需要虛擬主機的IP地址。本着容器中的「docker way」軟件的精神,容器本身應該在每個docker主機上運行。他們應該以任何方式依賴於主機的IP。 – kashian
我的意思是,如果我想通過測試到達我的本地網站。loc ServerName,我需要將機器的IP放在VirtualHost中。我有辦法確定自己機器的IP地址是否預先插入到虛擬主機中,並確保它不會更改? – jiboulex