apt-get 无法解析 docker 容器中的 url,即使容器可以正常解析它!

apt-get 无法解析 docker 容器中的 url,即使容器可以正常解析它!

这种情况很奇怪。我试图构建一个图像,但apt-get update失败了。不过网络工作正常。DNS 没问题,我甚至可以正常 wget 相同的 URL!!

查看终端输出:

❯ docker run -i -t python /bin/bash

root@e0264555b919:/# apt-get update
Err:1 http://deb.debian.org/debian bullseye InRelease
  Temporary failure resolving 'deb.debian.org'
Err:2 http://deb.debian.org/debian-security bullseye-security InRelease
  Temporary failure resolving 'deb.debian.org'
Err:3 http://deb.debian.org/debian bullseye-updates InRelease
  Temporary failure resolving 'deb.debian.org'
Reading package lists... Done
W: Failed to fetch http://deb.debian.org/debian/dists/bullseye/InRelease  Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://deb.debian.org/debian-security/dists/bullseye-security/InRelease  Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/bullseye-updates/InRelease  Temporary failure resolving 'deb.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.

root@e0264555b919:/# wget http://deb.debian.org/debian/dists/bullseye-updates/InRelease
--2023-01-07 11:50:33--  http://deb.debian.org/debian/dists/bullseye-updates/InRelease
Resolving deb.debian.org (deb.debian.org)... 151.101.62.132, 2a04:4e42:f::644
Connecting to deb.debian.org (deb.debian.org)|151.101.62.132|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 44066 (43K)
Saving to: ‘InRelease’

InRelease                   100%[==========================================>]  43.03K  --.-KB/s    in 0.01s

2023-01-07 11:50:33 (3.84 MB/s) - ‘InRelease’ saved [44066/44066]

root@e0264555b919:/# head InRelease
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Origin: Debian
Label: Debian
Suite: stable-updates
Version: 11-updates
Codename: bullseye-updates
Date: Sat, 07 Jan 2023 08:40:57 UTC
Valid-Until: Sat, 14 Jan 2023 08:40:57 UTC

root@e0264555b919:/# cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 1.1.1.1

root@e0264555b919:/#

知道为什么会这样吗?我试了几个基于 Debian 的图像,都是同样的问题!

答案1

显然,问题在于 docker 根目录位于具有用户所有权(而非 root )的 ntfs 分区中。

我移动了它,因为/空间不足,而且似乎/etc/resolv.conf文件已安装在所有容器上。apt-get 出于某种原因不喜欢这样,无法读取它。

我重新安装了 docker/var/lib/docker作为默认根目录,debian 容器现在可以正常工作。

所以,我想我需要一个根拥有的分区才能移动 docker 根目录。

答案2

输入“apt-get update”后出现此错误,看起来像是没有外部访问权限。尝试通过 curl -I 进行测试https://google.com 或者直接 ping google.com

相关内容