Docker 忽略本地 DNS 设置

Docker ignoring local dns settings

我启动了一个 jenkins-k8s-slave,它应该从本地注册表中提取。为什么 docker 忽略由 kubernetes 管理的本地 DNS 设置(/etc/hosts/etc/resolv.conf)?

当我这样做时:

docker pull service.namespace.svc.cluster.local:5000/test:latest

我得到:dial tcp: lookup service.namespace.svc.cluster.local: no such host

但这行得通:

curl https://service.namespace.svc.cluster.local:5000/v2/_catalog -k {"repositories":[...]}

您将需要配置 docker 以使用您的 dns,无论是什么,在这种情况下,您似乎需要告诉 docker 使用 kubernetes dns:

https://github.com/moby/moby/issues/23910

示例配置:

cat /etc/docker/daemon.json

{
    "hosts": [ "unix:///var/run/docker.sock","tcp://0.0.0.0:2376"],
    "live-restore": true,
    "tls": true,
    "tlscacert": "/etc/docker/ssl/ca.pem",
    "tlscert": "/etc/docker/ssl/cert.pem",
    "tlskey": "/etc/docker/ssl/key.pem",
    "tlsverify": true,
    "dns":["172.21.1.100","172.16.1.100"]
}

另请参阅: https://forums.docker.com/t/docker-pull-not-using-correct-dns-server-when-private-registry-on-vpn/11117/29