[英]How to configure host machine to access Apache ServeName in Docker
How to configure my Dockerfile or docker-compose for that my host machine can resolve a ServerName like http://myapp.env instead http://localhost:8080 ?! 如何为我的主机配置我的Dockerfile或docker-compose可以解析像http://myapp.env这样的ServerName而不是http:// localhost:8080 ?!
I tried to configure my local hosts file with the ip from container, but without success, like this 我试图使用来自容器的ip配置我的本地主机文件,但没有成功,就像这样
172.20.0.3 goforce.env 172.20.0.3 goforce.env
My Dockerfile 我的Dockerfile
FROM php:7.2-apache
LABEL maintainer="rIckSanchez"
LABEL project="MyApp"
COPY .docker/php/php.ini /usr/local/etc/php/
COPY .docker/apache/000-default.conf /etc/apache2/sites-available/
COPY . /srv/app
RUN apt-get update && apt-get install --no-install-recommends -y \
wget \
nano \
git \
unzip \
iputils-ping
# Install PHP extensions deps
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
zlib1g-dev \
libicu-dev \
g++ \
unixodbc-dev \
libxml2-dev \
libaio-dev \
libmemcached-dev \
freetds-dev \
libssl-dev \
openssl
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/local/bin \
--filename=composer
# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-configure pdo_dblib --with-libdir=/lib/x86_64-linux-gnu \
&& pecl install sqlsrv-4.1.6.1 \
&& pecl install pdo_sqlsrv-4.1.6.1 \
&& pecl install redis \
&& pecl install memcached \
&& docker-php-ext-install \
iconv \
mbstring \
intl \
gd \
mysqli \
pdo_mysql \
pdo_dblib \
soap \
sockets \
zip \
pcntl \
ftp \
&& docker-php-ext-enable \
sqlsrv \
pdo_sqlsrv \
redis \
memcached \
opcache
RUN a2enmod rewrite negotiation
RUN chown -R www-data:www-data /srv/app
RUN service apache2 restart
My docker-compose 我的码头工人组成
version: "3"
networks:
app-tier:
driver: bridge
services:
app:
image: laravel-app
container_name: laravel-app
networks:
- app-tier
build:
context: .
dockerfile: .docker/Dockerfile
depends_on:
- redis
ports:
- 8080:80
volumes:
- .:/srv/app
redis:
image: redis:4-alpine
container_name: laravel-redis
networks:
- app-tier
ports:
- 16379:6379
volumes:
- redis:/data
volumes:
redis:
driver: "local"
My 000-default.conf file 我的000-default.conf文件
<VirtualHost *:80>
ServerName myapp.env
ServerAdmin webmaster@localhost
DocumentRoot /srv/app/public
<Directory "/srv/app/public">
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Your docker web server port 80 is mapped to your localhost port 8080. To go around the the fact that localhost can't see the docker private network. 您的Docker Web服务器端口80映射到您的localhost端口8080。要绕过localhost无法看到Docker专用网络的事实。 The dns won't be able to map traffic to certain port, but you can access goforce.env:8080 by adding following line to your /etc/hosts file:
dns无法将流量映射到某些端口,但是您可以通过在/ etc / hosts文件中添加以下行来访问goforce.env:8080:
127.0.0.1 goforce.env
If you want to use just goforce.env, you should change your docker-compose: 如果只想使用goforce.env,则应更改docker-compose:
ports:
- 8080:80 -> to 80:80
or you could run apache proxy on your host machine and point port 80 to 8080 (if you must run apache on host and docker server at the same time). 或者您可以在主机上运行apache代理并将端口80指向8080(如果必须同时在主机和docker服务器上运行apache)。
Try using nginx for reverse proxy of the application . 尝试使用nginx进行应用程序的反向代理。 Check this url
检查这个网址
Multiple docker containers accessible by nginx reverse proxy Nginx反向代理可访问多个Docker容器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.