简体   繁体   English

Dockerized Apache服务器未公开端口80

[英]Dockerized apache server not exposing port 80

I am trying to run a React application inside a docker container. 我正在尝试在Docker容器中运行React应用程序。 My application image was built with the following Dockerfile: 我的应用程序映像是使用以下Dockerfile构建的:

Dockerfile Docker文件

FROM node:latest
LABEL autor="Ed de Almeida"

RUN apt-get update
RUN apt-get install -y apache2
RUN mkdir /tmp/myapp
COPY . /tmp/myapp
RUN cd /tmp/myapp && npm install
RUN cd /tmp/myapp && npm run build
RUN cd /tmp/myapp/build && cp -Rvf * /var/www/html
RUN cd /var/www && chown -Rvf www-data:www-data html/
EXPOSE 80

ENV APACHE_RUN_USER www-data
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

CMD /usr/sbin/apache2ctl -D FOREGROUND

As you may see, I create a production build, copy it to the standard directory of the Apache server and then run the Apache server. 如您所见,我创建了一个生产版本,将其复制到Apache服务器的标准目录中,然后运行Apache服务器。 I even exposed port 80, the Apache default port. 我什至公开了端口80(Apache默认端口)。

I am creating the image with 我正在创建图像

docker build -t myimage .

and running the container with 然后运行容器

docker run -d -p 80:80 --name myapp myimage

I am probably missing something, because I am new to Docker, because the container is there, up and running, but when I point my browser to http://localhost I got nothing. 我可能会丢失一些东西,因为我是Docker的新手,因为容器在那里并且可以运行,但是当我将浏览器指向http:// localhost时,我什么也没得到。

I entered the container with 我带着

docker exec -it myapp bash

and the application is running fine inside it. 并且应用程序在其中运行良好。

Any hints? 有什么提示吗?

When running on windows, Docker will be running on a virtual machine that is running in the backgound. 在Windows上运行时,Docker将在背景中运行的虚拟机上运行。 Thus you need to connect to this virtual machine and not to localhost. 因此,您需要连接到该虚拟机而不是本地主机。

You can get the machine ip by running: 您可以通过运行以下命令获取机器的IP:

docker-machine ip default

This will give you the IP address of the machine, which you can use to connect from the browser. 这将为您提供计算机的IP地址,您可以使用该IP地址从浏览器进行连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM