概述
Docker容器中的Linux机器快速设置国内源
在Docker容器中启动了服务后,当我们进入容器内,经常很多命令无法使用,比如最基本的vim,可能都没有安装,因为容器内只安装应用服务,导致无法编辑配置文件,当我们需要按照一些软件的时候,会发现使用apt update或者yum update等命令的时候,居然网络几乎卡死,因为Docker容器启动的镜像的sources.list里面配置源都是默认的,下载软件都是从国外的服务器上获取的,如果我们要修改sources.list时,发现连vim命令都没法使用,这时的解决办法就是,先exit容器,回到宿主机,使用find / -name sources.list命令,找到容器的sources.list文件
查看版本
获取debian系发行版的debian版本:cat /etc/*version
Ubuntu版本 | debian版本号 | debian代号 |
---|---|---|
14.04 | 8 | jessie |
16.04 | 9 | strech |
18.04 | - | buster |
在宿主机中查询容器的源配置文件
- find / -name sources.list
Docker容器的源配置文件结果如上
在宿主机中使用vim命令修改源配置文件
sudo vim /var/lib/docker/overlay2/0af11df29689803a4a4dba1487675cfdc6cf736d6042592735e72b9556df79a3/merged/etc/apt/sources.list
Debian jessie版本
deb http://mirrors.aliyun.com/debian/ jessie main non-free contrib
deb http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib
deb http://mirrors.aliyun.com/debian-security jessie/updates main
deb-src http://mirrors.aliyun.com/debian/ jessie main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib
Debian stretch版本
deb http://mirrors.aliyun.com/debian stretch main
deb http://mirrors.aliyun.com/debian-security stretch/updates main
deb http://mirrors.aliyun.com/debian stretch-updates main
Debian buster版本
deb http://mirrors.aliyun.com/debian buster main
deb http://mirrors.aliyun.com/debian-security buster/updates main
deb http://mirrors.aliyun.com/debian buster-updates main
好吧,阿里云的镜像仓库中,目前还没有最新版本buster的镜像,我刚才试过了不过有清华大学的镜像库
#注释原文件所有内容,用以下内容替代
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib
Ubuntu xenial版本 Ubuntu16.04版本
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
Ubuntu 18.04版本
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
其他方法
进入到容器中,使用一键替换命令 Ubuntu 14.04版/16.04版/18.04版
sudo curl -L https://github.com/AndyYoungDev/ubuntu-aliyun-sources/releases/download/shell/change.sh | bash
更新国内源后测试速度
速度:8MB/s,是不是很快呢?
最后
以上就是甜美机器猫为你收集整理的Docker容器中的Linux机器快速设置国内源Docker容器中的Linux机器快速设置国内源的全部内容,希望文章能够帮你解决Docker容器中的Linux机器快速设置国内源Docker容器中的Linux机器快速设置国内源所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复