我的设备:
- Linux Mint 20
- Docker版本19.03.12
- Cisco AnyConnect 4.3.05017
我的问题:
当我连接到公司的VPN时,我无法通过我的docker容器访问互联网。
例如运行docker run -it ubuntu apt update
会失败,并显示以下错误信息:“Err:1 http://archive.ubuntu.com/ubuntu focal InRelease
Temporary failure resolving 'archive.ubuntu.com'
断开VPN连接不能解决这个问题。(见解决方法#2)
我有两种解决方法:
- 使用
docker run -it --net=host ubuntu apt update
命令运行docker,这可以正常工作,但对于我的公司脚本和构建系统来说不是一个适合的解决方法。它只适合临时任务。 - 断开VPN连接并运行以下脚本(来自https://github.com/moby/moby/issues/36151):
# /bin/bash
docker system prune -a
systemctl stop docker
iptables -F
ip link set docker0 down
brctl delbr docker0
systemctl start docker
我尝试让Docker重新工作,但这样一来我就无法访问我的公司内部服务器,而这也是构建我们软件所必需的。
我尝试过以下几种方法:
- 在daemon.json中添加DNS (我的Docker容器没有网络)
- 修复resolv.conf (我的Docker容器没有网络)
- https://superuser.com/questions/1130898/no-internet-connection-inside-docker-containers
- Docker容器只能使用--net=host访问互联网
- https://dev59.com/3FsW5IYBdhLWcg3wAjKm#35519951
- 以及在谷歌搜索“docker container no internet behind vpn”的前两页结果中的任何其他结果