替换docker容器默认的debian镜像

半兽人 发表于: 2020-04-29   最后更新时间: 2020-04-29 14:21:43  
{{totalSubscript}} 订阅, 4,324 游览

在容器里执行apt-get命令时候,报如下错误,替换国内的镜像源即可。

apt-get install net-tools
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package net-tools
root@cloud-front-769f97f7b8-mvzjp:/# apt-get update           
Ign http://security.debian.org wheezy/updates Release.gpg                      
Ign http://security.debian.org wheezy/updates Release                          
Get:1 http://nginx.org wheezy Release.gpg [287 B]                      
Get:2 http://nginx.org wheezy Release [2343 B]                                 
Ign http://nginx.org wheezy Release                                            
Get:3 http://nginx.org wheezy/nginx amd64 Packages [31.9 kB]            
Err http://security.debian.org wheezy/updates/main amd64 Packages              

Err http://security.debian.org wheezy/updates/main amd64 Packages              

Err http://security.debian.org wheezy/updates/main amd64 Packages              

Err http://security.debian.org wheezy/updates/main amd64 Packages              

Err http://security.debian.org wheezy/updates/main amd64 Packages
  404  Not Found [IP: 151.101.128.204 80]
Ign http://http.debian.net wheezy Release.gpg                   
Ign http://http.debian.net wheezy-updates Release.gpg
Ign http://http.debian.net wheezy Release
Ign http://http.debian.net wheezy-updates Release
Err http://http.debian.net wheezy/main amd64 Packages                          

Err http://http.debian.net wheezy-updates/main amd64 Packages                  

Err http://http.debian.net wheezy/main amd64 Packages                          

Err http://http.debian.net wheezy-updates/main amd64 Packages                  

Err http://http.debian.net wheezy/main amd64 Packages                          

Err http://http.debian.net wheezy-updates/main amd64 Packages                  

Err http://http.debian.net wheezy/main amd64 Packages                          

Err http://http.debian.net wheezy-updates/main amd64 Packages                  

Err http://http.debian.net wheezy/main amd64 Packages                          
  404  Not Found
Err http://http.debian.net wheezy-updates/main amd64 Packages                  
  404  Not Found
Fetched 34.6 kB in 12s (2774 B/s)                                              
W: GPG error: http://nginx.org wheezy

使用163的源

# 更新apt-get源
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
    echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list && \
    echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list && \
    echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list && \
    echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list

使用阿里云的源

# 更新apt-get源
mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
echo "deb http://mirrors.aliyun.com/debian stretch main contrib non-free" >/etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/debian stretch main contrib non-free" >>/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/debian stretch-updates main contrib non-free" >>/etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/debian stretch-updates main contrib non-free" >>/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free" >>/etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free" >>/etc/apt/sources.list
更新于 2020-04-29

中华天朝 6月前

阿里云的源的配置似乎有点旧了,可参考官网提供的方式更新一下: https://developer.aliyun.com/mirror/debian

查看kubernetes更多相关的文章或提一个关于kubernetes的问题,也可以与我们一起分享文章