1、问题描述:
- 新建docker容器
docker run -it --rm ubuntu:18.04
- 执行
apt update
,报错:bash: ping: command not found root@d087aa834821:/# apt update Ign:1 http://security.ubuntu.com/ubuntu bionic-security InRelease Ign:2 http://archive.ubuntu.com/ubuntu bionic InRelease Ign:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease Err:4 http://security.ubuntu.com/ubuntu bionic-security Release 404 [IP: 91.189.91.38 80] Ign:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease Err:6 http://archive.ubuntu.com/ubuntu bionic Release 404 [IP: 91.189.88.142 80] Err:7 http://archive.ubuntu.com/ubuntu bionic-updates Release 404 [IP: 91.189.88.142 80] Err:8 http://archive.ubuntu.com/ubuntu bionic-backports Release 404 [IP: 91.189.88.142 80] Reading package lists... Done E: The repository 'http://security.ubuntu.com/ubuntu bionic-security Release' does not have 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://archive.ubuntu.com/ubuntu bionic Release' does not have 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://archive.ubuntu.com/ubuntu bionic-updates Release' does not have 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://archive.ubuntu.com/ubuntu bionic-backports Release' does not have 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、解决方法:
方法1:新建docker时指定参数--network=host
:
docker run -itd --rm --network=host ubuntu:18.04 /bin/bash
方法2:重置docker0( docker0为docker的默认网桥)
# 杀死docker进程
pkill docker
# 清空nat表的所有链
iptables -t nat -F
#停止docker默认网桥
ifconfig docker0 down
#删除docker默认网桥
brctl delbr docker0
#
docker -d
#重启docker
systemctl restart docker
-
查看网络基本信息
ifconfig
-
查看网桥
brctl show
方法3:修改docker默认配置文件
-
查看文件
/etc/default/docker
vi /etc/default/docker
-
文件内容中的
DOCKER_OPTS
选项为:DOCKER_OPTS =“-dns 8.8.8.8 –dns 8.8.4.4”
-
查看本机dns
cat /etc/resolv.conf
-
输出为:
# This file is managed by man:systemd-resolved(8). Do not edit. # # This is a dynamic resolv.conf file for connecting local clients to the # internal DNS stub resolver of systemd-resolved. This file lists all # configured search domains. # # Run "systemd-resolve --status" to see details about the uplink DNS servers # currently in use. # # Third party programs must not access this file directly, but only through the # symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way, # replace this symlink by a static file or a different symlink. # # See man:systemd-resolved.service(8) for details about the supported modes of # operation for /etc/resolv.conf. nameserver 127.0.0.53 options edns0
很明显docker参数中的dns地址与本机实际地址不一致,此时只需要注释掉
DOCKER_OPTS
参数即可。 -
重启docker
systemctl restart docker
更多推荐