如果是新的容器的话是没有vim的,所以只能用流来写进去:
但是要注意,用下面的指令查看docker容器中的linux系统版本:
cat /etc/issue
查出自己系统的版本之后,去找对应的开发代号,比如Ubuntu18.04 LTS 对应的开发代号叫Bionic,以下是不同系统版本对应的代号:
参考链接:Ubuntu 各版本号和名称对照
然后,把自己系统对应的代号在下面修改好之后再运行到容器中,下面给出常用的Ubuntu16和18的例子,其他的要自己修改啦。
Ubuntu16.04 LTS
cat > /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
EOF
Ubuntu18.04 LTS
cat > /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
EOF