5

Docker容器更换国内软件源

 2 years ago
source link: https://fisher.lazybone.xyz/docker%E5%AE%B9%E5%99%A8%E6%9B%B4%E6%8D%A2%E5%9B%BD%E5%86%85%E8%BD%AF%E4%BB%B6%E6%BA%90.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Docker容器更换国内软件源

发表于

2020-07-19

阅读次数: 11

Docker容器使用apt作为软件包管理器,并且默认软件源是国外服务器,更新源和下载软件的速度都非常慢,因此需要更换为国内的软件源。但由于容器十分纯净,甚至连vi和vim都没有,不能通过编辑器打开修改软件源配置文件,关于这个问题的解决方法,我们可以使用shell的管道直接修改软件源配置文件。

我们可以通过管道来将国内软件源地址写入到配置文件中,具体操作如下:

  1. 进入容器,备份yum源配置文件

    docker exec -it container bash
    mv /etc/apt/sources.list /etc/apt/sources.list.bak
  2. 写入国内软件源地址,此处用的是网易的软件源

    cat > /etc/apt/sources.list << EOF
    deb http://mirrors.163.com/debian/ buster main contrib non-free
    # deb-src http://mirrors.163.com/debian/ buster main contrib non-free
    deb http://mirrors.163.com/debian/ buster-updates main contrib non-free
    # deb-src http://mirrors.163.com/debian/ buster-updates main contrib non-free
    deb http://mirrors.163.com/debian/ buster-backports main contrib non-free
    # deb-src http://mirrors.163.com/debian/ buster-backports main contrib non-free
    deb http://mirrors.163.com/debian-security buster/updates main contrib non-free
    # deb-src http://mirrors.163.com/debian-security buster/updates main contrib non-free
    EOF

    写入配置

  3. 更新apt软件包索引

    apt update

    更新包索引

  4. 安装所需要的软件包,完成!

    apt install vim -y

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK