How to detect whether docker supports host.docker.internal

To check if your Docker supports host.docker.internal hostname, you can try the following steps:

1. Start the sh temporary container

Run a temporary container: Use the following command to start a temporary container in interactive mode.

docker run -it --rm alpine sh

This will start an interactive shell inside the Alpine Linux container.

2. Query analysis

Make a DNS lookup in the container: From the container's shell prompt, run the following command to make a DNS lookup:

nslookup host.docker.internal

If you see output similar to the following, your Docker supports host.docker.internal :

Server:    192.168.65.1
Address 1: 192.168.65.1

Name:      host.docker.internal
Address 1: 192.168.X.X   # 宿主机的 IP 地址

If the output shows the IP address of the host machine, then Docker supports the host.docker.internal hostname.
If the query fails or displays another error message, it's possible that your version of Docker does not support host.docker.internal .

Note that host.docker.internal is a special hostname for Docker Desktop (Mac and Windows). It provides an easy way to access services on the host machine. However, this hostname may be supported differently in different Docker versions and environments.
If your version of Docker does not support host.docker.internal, you can try to use the IP address of the host machine instead.

3. Supplementary instructions

1、nslookup

nslookup is mainly used to diagnose Domain Name System (DNS) infrastructure information. Query DNS records, check whether the domain name resolution is normal, and use it to diagnose network problems when the network fails.

Grammar format:

nslookup [-option] [name | -] [server]

Common usage:

nslookup 163.com
nslookup 163.com 223.5.5.5	//指定DNS服务器

insert image description here

2. Query the ip of the linux host

ifconfig
ip addr

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/bobo789456123/article/details/130866328