从主机查询 docker 内嵌的 dns [英] Query docker embedded dns from host

查看:51
本文介绍了从主机查询 docker 内嵌的 dns的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道查询 docker 守护进程使用的嵌入式 dns 服务器的方法.我正在尝试使用 packetbeats,如果我可以用容器名称替换 docker ip 地址会很有用.

Does anybody know a way to query the embedded dns server that the docker daemon uses. I'm experimenting with packetbeats and it would be useful if I could replace docker ip addresses with the container names.

我目前想到的唯一实现方法是在容器中创建一个可以配置为主机的dns服务器的dns服务器,以确保主机可以解析容器名称.希望这是有道理的?

The only way I can currently think of to achieve this is to create a dns server in a container that can be configured as the dns server for the host to ensure container names can be resolved by the host. Hope that makes sense?

这是唯一的方法还是有其他选择?

Is this the only way or are there other options ?

我尝试查询的容器是使用 docker-compose 创建的.

The containers I'm trying to query were created using docker-compose.

推荐答案

Consul

我喜欢为此使用 Hashicorp 的 Consul.它可以作为已安装的客户端或容器运行,并提供一个 DNS 接口,您可以在 Docker 外部查询.它还具有服务发现等功能.监控,并且是开源的.

Consul

I like using Hashicorp's Consul for this. It can run as an installed client or container, and provides a DNS Interface that you can query external of Docker. It also has features like service discovery & monitoring, and is open source.

https://www.consul.io/docs/agent/dns.html

Consul 的主要查询接口之一是 DNS.DNS 接口允许应用程序利用服务发现,而无需与 Consul 进行任何高度接触.

One of the primary query interfaces for Consul is DNS. The DNS interface allows applications to make use of service discovery without any high-touch integration with Consul.

例如,主机可以通过名称查找(如redis.service.east-aws.consul")直接使用 DNS 服务器,而不是向 Consul 发出 HTTP API 请求.此查询自动转换为查找提供 redis 服务的节点,这些节点位于east-aws"节点中.数据中心,并且没有失败的健康检查.就这么简单!

For example, instead of making HTTP API requests to Consul, a host can use the DNS server directly via name lookups like "redis.service.east-aws.consul". This query automatically translates to a lookup of nodes that provide the redis service, are located in the "east-aws" datacenter, and have no failing health checks. It's that simple!

对于您正在寻找的内容来说,这可能有点过头了,但应该可以.

It might be overkill for what you're looking for, but should do the job.

一个更简单的替代方案可能是 DNSMasq.我不太熟悉它,但对于非常小规模的设置,它可以让您的主机通过 DNS 识别正在运行的容器.

A simpler alternative might be DNSMasq. I'm not as familiar with it, but for a really small scale setting it would allow your host to be DNS aware of running containers.

http://www.thekelleys.org.uk/dnsmasq/doc.html

https://hub.docker.com/r/andyshinn/dnsmasq/

这篇关于从主机查询 docker 内嵌的 dns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆