[英]How to make docker container on mac accessible by other PC on same network
I currently have several containers running inside docker which is handled by docker-compose file.我目前有几个容器在 docker 内运行,这些容器由 docker-compose 文件处理。
The roughly content of the docker compose file looks like below docker 撰写文件的大致内容如下所示
app1:
container_name: app1
depends_on:
- app2
image: someimagepath
build:
context: ./app1
dockerfile: Dockerfile
ports:
- 127.0.0.1:81:80
expose:
- "80"
networks:
- datanet
app2:
....
Question: How can I make it so that the app1 can be accessible by my other PC so that I can hit the URL like http://<LAN-IP>: 80
and connect to it?问题:我怎样才能使我的另一台 PC 可以访问 app1,以便我可以像
http://<LAN-IP>: 80
一样点击 URL 并连接到它?
Thanks谢谢
Your PC needs to access the Mac, so it needs the IP address of the Mac (suppose 192.168.1.3).您的 PC 需要访问 Mac,因此需要 Mac 的 IP 地址(假设为 192.168.1.3)。
Suppose your Mac has Internal Network IP 192.168.1.3 From the PC you do: http://192.168.1.3 But then it enter the Mac on port 80.假设您的 Mac 有内部网络 IP 192.168.1.3 从您的 PC 执行: http://192.168.1.3但随后它通过端口 80 进入 Mac。
Somehow you need to forward requests on the Mac to port 80 to your App1 Container.不知何故,您需要将 Mac 上的请求转发到端口 80 到您的 App1 容器。 You need a ProxyServer for that, like Nginx.
为此,您需要一个 ProxyServer,例如 Nginx。
Basically is comes down to realising that your PC cannot access a Docker Container running on another system directly.基本上归结为意识到您的 PC 无法直接访问在另一个系统上运行的 Docker 容器。 You something on the Host (where the container is running) to forward requests to that container.
您在主机(容器正在运行的地方)上的某些东西将请求转发到该容器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.