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

前端 未结 9 1141
面向向阳花
面向向阳花 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:30

    Depends what you're trying to do. If you're running with --net=host, localhost should work fine. If you're using default networking, use the static IP 172.17.0.1. I suspect neither will behave quite the same as those domains.

    0 讨论(0)
  • 2020-12-02 10:31

    Using the docker0 interface ip, say 172.17.0.1, could be a good workaround.

    Just be sure that the service you need to reach listens to external connections. A typical example is Mysql who binds to 127.0.0.1 by default, resulting unreachable until you allow external connections (es. binding to 0.0.0.0)

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题