简体   繁体   English

如何在启用自定义 dns 配置的情况下使 host.docker.internal 工作?

[英]How do I make host.docker.internal work with custom dns configuration enabled?

I have docker compose running with several containers.我有 docker 组合运行多个容器。 One of those containers is a dns server running bind.其中一个容器是运行绑定的 dns 服务器。 In my docker daemon configuration I specify the dns like this:在我的 docker 守护程序配置中,我像这样指定 dns:

"dns" : [
  "10.1.1.8", /* static ip address of my dockerized bind container defined in compose */
  "x.x.x.x", /* my companies internal vpn dns */
  "8.8.8.8" /* google dns */
]

This all works fine.这一切都很好。 My containers in the compose file will use the bind server running on 10.1.1.8 for dns lookup and then fall back on my companies internal dns and lastly googles dns for external websites.我在撰写文件中的容器将使用在 10.1.1.8 上运行的绑定服务器进行 dns 查找,然后使用我公司内部的 dns,最后使用谷歌搜索 ZB3BF60B851EBAEB2768B01A32E2EF3 外部网站。

Docker provides a special dns host.docker.internal which should point at the host IP (lets say you want docker containers to connect to services running locally but not on docker). Docker provides a special dns host.docker.internal which should point at the host IP (lets say you want docker containers to connect to services running locally but not on docker). I want to use this in a few containers which should allow the container to reference the host IP address without hardcoding an IP which can change.我想在几个容器中使用它,这应该允许容器引用主机 IP 地址,而无需硬编码可以更改的 IP。 In fact docker inserts this value into the hosts file (windows/system32/driver/etc/host) on the host operating system and updates it when you host IP gets assigned a new dns.事实上,docker 将此值插入到主机操作系统上的主机文件(windows/system32/driver/etc/host)中,并在您托管 IP 时对其进行更新,并分配一个新的 ZB3BF60B851EBAEB23768B01A32E。

The issue is docker uses dns to resolve "host.docker.internal".问题是 docker 使用 dns 来解决“host.docker.internal”。 When using my custom dns configuration in the daemon it breaks things and I get issues reaching the host os service.在守护程序中使用我的自定义 dns 配置时,它会破坏事情并且我在到达主机操作系统服务时遇到问题。 I spent 2 hours debugging this issue till I realized host.docker.internal starts working only when I delete the dns configuration from the daemon config.我花了 2 个小时调试这个问题,直到我意识到 host.docker.internal 仅在我从守护程序配置中删除 dns 配置时才开始工作。 Is there any way to make docker resolve the dns correctly and still use custom dns bind server on the same machine?有什么方法可以让 docker 正确解析 dns 并且仍然在同一台机器上使用自定义 dns 绑定服务器? Can I somehow update the daemon dns to also point at some docker dns ip address?我可以以某种方式更新守护程序 dns 以也指向一些 docker dns Z957B527BCFBAD2E380F58D20635 地址吗?

Have you considered to rely on Docker Compose and how it helps defining custom DNS addressing policies.您是否考虑过依赖Docker Compose以及它如何帮助定义自定义 DNS 寻址策略。

I provide you the link to the Compose DNS configuration official guide .我为您提供了Compose DNS 配置官方指南的链接。

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

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