[英]How to make an app running inside a docker container available to the local network?
I am given access to a docker container, I use ssh to get inside the container.我可以访问 docker 容器,我使用 ssh 进入容器。
ssh user@192.168.1.76 -p 2222
Now, I have deployed an app inside the docker container (from the container), in port 8000.现在,我已经在 docker 容器(来自容器)中的 8000 端口部署了一个应用程序。
How can I access the app from my local network?如何从本地网络访问应用程序?
NB: I tried sudo ufw allow 8000
, and hostname -a
to get the IP, but can't access the app on IP:8000
from the local network.注意:我尝试
sudo ufw allow 8000
和hostname -a
来获取 IP,但无法从本地网络访问IP:8000
上的应用程序。
Now, the container was run with --net=host
, so all the ports of the container are mapped to the host ones.现在,容器使用
--net=host
运行,因此容器的所有端口都映射到主机端口。 So, I had to change the host in app to 0.0.0.0
to get the app live in the local network.因此,我必须将应用程序中的主机更改为
0.0.0.0
才能使应用程序在本地网络中运行。
Use -p 8000:8000
as an argument to docker run
.使用
-p 8000:8000
作为docker run
的参数。 Then you can access this port with the IP of the host machine.然后就可以用宿主机的IP访问这个端口了。
Reference: https://docs.docker.com/network/host/参考: https://docs.docker.com/network/host/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.