无法使用 apt-get update 更新 ubuntu Docker 容器

无法使用 apt-get update 更新 ubuntu Docker 容器

当我将 ubuntu 作为 Docker 容器运行时,当我运行apt-get update命令时,它出现错误并且无法更新存储库。

以下是我遇到的错误:

root@df167e514b29:/# sudo bash: sudo: command not found root@df167e514b29:/# apt-get update Err:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Temporary failure resolving 'archive.ubuntu.com' Err:2 http://security.ubuntu.com/ubuntu bionic-security InRelease
Temporary failure resolving 'security.ubuntu.com' Err:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease Temporary failure resolving 'archive.ubuntu.com' Err:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease Temporary failure resolving 'archive.ubuntu.com' Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease Temporary failure resolving 'security.ubuntu.com' W: Some index files failed to download. They have been ignored, or old ones used instead. root@df167e514b29:/#

答案1

问题出在互联网连接上,因为我的连接是企业级的,因此无法执行apt-get update命令。对我有用的解决方案是:

  1. 使用以下方式查找您的 DNS 服务器地址cat /etc/resolv.conf

  2. 打开 Docker confg 文件并取消注释DOCKER_OPTS,然后在那里添加你的 DNS 服务器

Docker 配置文件:sudo gedit /etc/default/docker

相关内容