docker运行Ubuntu:latest容器,无法连接网络,apt-get报错
一、状态
自己制作的arm架构的Ubuntu18系统,docker版本是18.06.03,拉取最新的Ubuntu镜像,在镜像内使用apt-get update命令出现如下错误:
root@73387d64899b:/# apt-get update Err:1 http://deb.debian.org/debian buster InRelease Could not resolve 'deb.debian.org' Err:2 http://security.debian.org/debian-security buster/updates InRelease Could not resolve 'security.debian.org' Err:3 http://deb.debian.org/debian buster-updates InRelease Could not resolve 'deb.debian.org' Reading package lists... Done W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease Could not resolve 'deb.debian.org' W: Failed to fetch http://security.debian.org/debian-security/dists/buster/updates/InRelease Could not resolve 'security.debian.org' W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease Could not resolve 'deb.debian.org' W: Some index files failed to download. They have been ignored, or old ones used instead.
二、解决
1. 更改hosts文件,将静态ip添加进文件
root@73387d64899b:/# cat /etc/hosts 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 172.17.0.2 73387d64899b 151.101.128.204 deb.debian.org 151.101.78.133 security.debian.org
出现如下结果,还是有错误。
root@73387d64899b:/# apt-get update Ign:1 http://deb.debian.org/debian buster InRelease Ign:2 http://security.debian.org/debian-security buster/updates InRelease Ign:3 http://deb.debian.org/debian buster-updates InRelease Err:4 http://security.debian.org/debian-security buster/updates Release Could not create a socket for 151.101.78.133 (f=2 t=1 p=6) - socket (13: Permission denied) Err:5 http://deb.debian.org/debian buster Release Could not create a socket for 151.101.128.204 (f=2 t=1 p=6) - socket (13: Permission denied) Err:6 http://deb.debian.org/debian buster-updates Release Could not create a socket for 151.101.128.204 (f=2 t=1 p=6) - socket (13: Permission denied) Reading package lists... Done E: The repository 'http://security.debian.org/debian-security buster/updates Release' no longer has a Release file. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. E: The repository 'http://deb.debian.org/debian buster Release' no longer has a Release file. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. E: The repository 'http://deb.debian.org/debian buster-updates Release' no longer has a Release file. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details.
2. 更改/etc/passwd文件,将如下语句的gid:65534改为3003,解决问题
_apt:x:100:65534::/nonexistent:/usr/sbin/nologin
#改为:
_apt:x:100:3003::/nonexistent:/usr/sbin/nologin