简体   繁体   English

如何使在 docker 容器内运行的应用程序可用于本地网络?

[英]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 8000hostname -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.

相关问题 如何使运行Windows主机的Docker容器中的端口可用于本地网络 - How to make ports in a docker container running Windows host available to a local network 如何使Docker服务在本地网络上可用 - How to make docker service available at local network 在 docker 容器上运行的 Azure 应用服务中提供 *.crt *.pem 证书 - Make *.crt *.pem certificates available inside Azure App service running on docker container 如何在正在运行的 docker 容器内安装应用程序? - how to install an app inside of running docker container? 将 docker 服务容器内的应用程序连接到在外部网络 docker 容器上运行的数据库 - Connect an app inside docker service container to a database running on external network docker container 如何在我的Docker容器中提供ffmpeg? - How to make ffmpeg available inside my Docker container? 如何访问本地网络中的Docker容器? - How to access a Docker container in the local network? 如何将 Docker 容器连接到本地网络 - How to connect a Docker container to a local network 如何访问在 Docker 容器内运行的 Django 应用程序? - How to access the Django app running inside the Docker container? 如何将 CSV 文件传递​​给在 Docker 容器内运行的 Flask 应用程序? - How to pass a CSV file to a Flask app running inside a Docker container?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM