简体   繁体   English

当使用 nerdctl 代替 docker 时,应该使用什么来代替“host.docker.internal”?

[英]what should be used instead of 'host.docker.internal' when using nerdctl in place of docker?

When using docker desktop, we would connect to the host machine from the container using the URL 'host.docker.internal'.当使用 docker 桌面时,我们将使用 URL 'host.docker.internal' 从容器连接到主机。

however container is not able to connect to the host machine (ie my machine) when I am using nerdctl instead of docker.但是,当我使用nerdctl而不是 docker 时,容器无法连接到主机(即我的机器)。

I installed Rancher desktop to use nerdctl我安装了 Rancher 桌面以使用 nerdctl

ipconfig getifaddr en0

The above command will give the IP address of your wireless connection.上述命令将给出您的无线连接的 IP 地址。 Note, this will only work for MacOS.请注意,这仅适用于 MacOS。 This IP can then be written to the /etc/hosts of your container against host.docker.internal as they share the same network.这个 IP 然后可以针对host.docker.internal写入容器的 /etc/hosts,因为它们共享同一个网络。 This can help the container communicate to the host machine by using host.dock.internal .这可以帮助容器通过使用host.dock.internal与主机通信。 Although, an elegant solution is expected from RancherDesktop (or its already available in the newer versions).尽管如此,希望 RancherDesktop 提供一个优雅的解决方案(或者它已经在较新的版本中可用)。

From lima docs.来自利马文档。

The loopback addresses of the host is 192.168.5.2 and is accessible from the guest as host.lima.internal.主机的环回地址是 192.168.5.2,并且可以从来宾作为 host.lima.internal 访问。

So instead of host.docker.internal , provide 192.168.5.2所以代替host.docker.internal ,提供192.168.5.2

I have tested this with nerdctl distributed via Rancher and it works!我已经使用通过 Rancher 分发的 nerdctl 对此进行了测试,它可以工作!

reference: https://github.com/lima-vm/lima/blob/master/docs/network.md参考: https://github.com/lima-vm/lima/blob/master/docs/network.md

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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