一、背景
在部署 Elasticsearch 7.17.7 版本时,进入到改容器后,发现该镜像没有vi,同时使用apt也无法正常安装,于是百度找解决方案,一步一坑,最后完美解决。
二、解决
首先进入镜像中
docker exec -it es bash
直接安装 apt install vim ,提示出定位不到该包文件,再使用 apt update 进行更新镜像,发现连接不上 ubuntu 的库,需要修改镜像源,首先使用 mv 命令进行备份。
mv source.list source.list.bak
接着修改镜像源文件,但是没有 vi、nano等编辑命令,遂使用如下命令
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse" >> /etc/apt/sources.list
编辑好后再次尝试安装,运气好的话就可以进行安装了。当然我遇到了无法解析 mirrors.aliyun.com 的情况,则继续执行下面的步骤
echo "nameerver 114.114.114.114" >> /etc/resolv.conf
然后重启网卡,重启镜像,重启虚拟机。这里我是直接重启虚拟机后成功了。
重启完成之后
systemctl start docker
docker start es
docker exec -it es bash
apt update
apt install vim
vim