查看: 21|回覆: 0

[Ubuntu] Docker中 Ubuntu 容器 apt-get update网络访问失败解决办法

[複製鏈接]

1

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2010-2-4
發表於 2020-4-10 11:52:00 | 顯示全部樓層 |閲讀模式

学习Docker在Ubuntu容器中使用apt-get update命令遇到如下网络连接错误:

$ docker run -it ubuntu
root@3c5e3b049c88:/# 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.

搜索各种解决方案,改容器dns的,改容器ip的都有,过程都比较复杂,要想办法在容器内修改配置文件,或在容器外改好在通过数据绑定传入容器。

最后发现有人通过--net=host参数改变容器网络模式解决,实验后果然解决问题。

$ docker run -it --name test --net=host ubuntu
root@localhost:/# apt-get update
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]
Get:3 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [839 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]        
Get:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]       
Get:6 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [186 kB]  
Get:7 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [44.6 kB]
Get:8 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [8213 B]
Get:9 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [889 kB]     
Get:10 http://archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages [13.5 kB]      
Get:11 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [11.3 MB]
Get:12 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages [1344 kB]                                                           
Get:13 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [12.6 kB]                                             
Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [59.0 kB]                                             
Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [1183 kB]                                                   
Get:16 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1371 kB]                                               
Get:17 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [4247 B]                                              
Get:18 http://archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [2496 B]                                                  
Fetched 17.8 MB in 8s (2116 kB/s)                                                                                                      
Reading package lists... Done
root@localhost:/# 

 



来源:https://www.cnblogs.com/coffeebox/p/12672467.html
回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部