将docker debian中apt-get源替换为阿里云源并安装vim

将docker debian中apt-get源替换为阿里云源并安装vim
在使用docker haproxy镜像的时候,需要添加修改配置文件, 但是发现没有vi和vim编辑工具,于是乎需要自己安装。那么如何安装呢?

登入docker实例

[root@myserver1 ~]# docker exec -it haproxy1 /bin/bash
root@dc3d333fc181:/#

查看系统版本

root@dc3d333fc181:~# cat /etc/issue
Debian GNU/Linux 10 \n \l

我们使用Debian自带的apt-get进行安装即可。

方式一:默认源安装

执行apt-get update更新源

root@dc3d333fc181:~# apt-get update

更新完过后我们就可以安装了vim了

root@dc3d333fc181:~# apt-get install vim

以上的方式虽然可以实现安装vim,但是速度很慢。我们需要更快的方式

方式二:aliyun源安装

因为没有vi,vim编辑工具,我这里使用sed命令进行编辑文件内容。

首先查看默认源地址:

root@dc3d333fc181:~# cat /etc/apt/sources.list
# deb http://snapshot.debian.org/archive/debian/20191118T000000Z buster main
deb http://deb.debian.org/debian buster main
# deb http://snapshot.debian.org/archive/debian-security/20191118T000000Z buster/updates main
deb http://security.debian.org/debian-security buster/updates main
# deb http://snapshot.debian.org/archive/debian/20191118T000000Z buster-updates main
deb http://deb.debian.org/debian buster-updates main

从上面的输出内容我们可以看出,默认会从deb.debian.org去更新源信息。我们将其替换为aliyun的源地址:

root@dc3d333fc181:~# sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list

替换完源后我们就可以安装vim了

root@dc3d333fc181:~# apt-get clean
root@dc3d333fc181:~# apt-get update
root@dc3d333fc181:~# apt-get install vim

the end

热门文章