What is linux equivalent of “host.docker.internal”

前端 未结 9 1181
面向向阳花
面向向阳花 2020-12-02 09:37

On Mac and Windows it is possible to use docker.for.mac.host.internal (replaces docker.for.mac.localhost) and docker.for.win.host.int

9条回答
  •  长情又很酷
    2020-12-02 10:34

    One solution is to use a special container which redirects traffic to the host. You can find such a container here: https://github.com/qoomon/docker-host. The idea is to grab the default route from within the container and install that as a NAT gateway for incoming connections.

    An imaginary example usage:

    docker-host:
      image: qoomon/docker-host
      cap_add: [ 'NET_ADMIN', 'NET_RAW' ]
      restart: on-failure
      environment:
        - PORTS=999
    
    some-service:
      image: ...
      environment:
        SERVER_URL: "http://docker-host:999"
      command: ...
      depends_on:
        - docker-host
    

提交回复
热议问题