简体   繁体   中英

How to CNAME a domain to “host.docker.internal”?

I know "host.docker.internal" points to the host running docker daemon. I'd like to achieve the following:

services:
  xx:    
    extra_hosts: ["example.com:host.docker.internal"]

But I can only use a specific IP address in extra_hosts.

My question: Is there a way to do this?

If your docker version is above 20.04 , then you could use next:

extra_hosts:
  - "host.docker.internal:host-gateway"

Detail see this .

Then you could use host.docker.internal to communicate with host, eg:

$ docker run --rm -it --add-host=host.docker.internal:host-gateway debian:10 ping -c 4 host.docker.internal
PING host.docker.internal (172.17.0.1) 56(84) bytes of data.
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=1 ttl=64 time=0.064 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=2 ttl=64 time=0.094 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=3 ttl=64 time=0.094 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=4 ttl=64 time=0.095 ms

--- host.docker.internal ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 74ms
rtt min/avg/max/mdev = 0.064/0.086/0.095/0.017 ms

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM