• Docker中 Ubuntu 容器 aptget update网络访问失败解决办法


    学习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:/# 
  • 相关阅读:
    ubuntu下安装oracle
    网站框架策划时的小技巧--页面原型篇
    中国电商价格欺诈何时休?
    系统升级日记(4):如何快速的修改Infopath中的各种URL
    系统升级日记(3)- 升级SharePoint解决方案和Infopath
    系统升级日记(2)- 升级到SharePoint Server 2013
    系统升级日记(1)- 升级到SQL Server 2012
    【译】《C# Tips -- Write Better C#》
    [.NET] 一步步打造一个简单的 MVC 电商网站
    反骨仔的 2016 年度全文目录索引
  • 原文地址:https://www.cnblogs.com/coffeebox/p/12672467.html
Copyright © 2020-2023  润新知