简体   繁体   English

如何使同一网络上的其他 PC 可以访问 mac 上的 docker 容器

[英]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。

  1. create another Docker Container running Nginx, listening to port 80 on the Host (the Mac) This will make sure that requests to port 80 on the Mac are picked up by the Nginx Docker Container create another Docker Container running Nginx, listening to port 80 on the Host (the Mac) This will make sure that requests to port 80 on the Mac are picked up by the Nginx Docker Container
  2. The Nginx config file needs to forward requests on port 80 to your App1 Container This is a matter of proxy forwarding. Nginx 配置文件需要将端口 80 上的请求转发到您的 App1 容器这是代理转发的问题。 App1 can listen to any port, Nginx forwarding takes the right port. App1 可以监听任何端口,Nginx 转发采用正确的端口。 Many example of this on Nginx sites. 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.

相关问题 如何通过IP使其他网络机器可以访问Docker容器? - How to make Docker container accessible to other network machines through IP? 同一网络中的Docker容器无法访问同一网络中的其他容器 - docker container in same network cannot reach other container in same network 无法从主机网络上的其他计算机访问docker容器 - docker container is not accessible from other machines on host's network 如何使用 docker 容器作为同一网络中其他容器的路由器 - How to use docker container as a router for other containers in the same network 如何在docker-compose v3中通过本地网络访问容器? - How do I make a container accessible over the local network in docker-compose v3? 如何使容器仅对同一网络中的其他容器可见 - How to make container visible only to other containers within the same network 我如何使我的Docker容器可供主机以外的其他机器访问 - How do i make my docker container accessible to machines other than my host machines 从Docker容器获取网络上其他主机的MAC地址 - Get MAC address of other host on network from Docker container docker 容器无法与同一网络上的其他容器通信 - docker container can't communicate to other container on the same network 使用docker run无法从其他容器访问容器 - Container Not Accessible From Other Container with docker run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM