对于docker桌面内部的dns name host.docker.internal解答到允许网络访问主机的IP地址。使用牧场主桌面时是否有类似的东西?
在Docker桌面中填写一个运行的容器(例如Alpine Image),可以运行
docker exec alpine-container ping -c 2 host.docker.internal
使用Dockerd(Moby)在Rancher Desktop中使用Dockerd(Moby)运行时,将
--add-host=host.docker.internal:host-gateway
添加到您的docker run
命令将实现此行为。
docker run -it --add-host=host.docker.internal:host-gateway alpine cat /etc/hosts
或docker-compose:
# docker-compose.yml
my_app:
image: ...
extra_hosts:
- "host.docker.internal:host-gateway"
https://megamorf.gitlab.io/2020/09/19/access-native-services-native-services-on-docker-host-bost-via-host-host-host-docker-internal/#implementation-
我认为,在将带有集装箱的Rancher桌面用作容器运行时时,这不会起作用。在问题中提到的那样,这已经在牧场台式机中解决了。但是,对于可能遇到这个问题的Windows用户,可能需要一个防火墙规则。
根据常见问题可能需要以下规则。
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
对于较新的版本,它是:
New -new -netfirewallrule -displayName“ wsl” - 方向入口-interfacealias“ vethernet(wsl(hyper -v firewall))” - action允许此外,必须通过高架(作为管理员)PowerShell发出此命令。
有一个开放的github问题[0]。作为解决方法,直到关闭此功能,Rancher Labs成员的提示可能会有所帮助(至少在Linux/MacOS上运行Rancher Desktop时):
我不认为我们有一个符号名称,但是主机总是(在Linux和MacOS上)可以通过192.168.5.2访问,这是QEMU网关地址。 [1]