以在Docker容器中安装vim为例
linux系统没有vim工具太不方便了,我要在docker容器里修改一些文件,所以决定安装下vim。系统是centos7.8
首先启动容器,指定能够连接外网的网络模式,
(不了解容器网络模式)点这里
[root@hostlocal ~]# docker run -tid --name myweb -p 81:80 4037a5562 f49b15115297a05f1af574f7eb1c0123f6e5f25b7abf790ba13175bc25a23013
进入容器
[root@hostlocal ~]# docker exec -it f49b15115297a bash root@f49b15115297:/#
接下来更新下apt-get的源。把下面的命令全部复制粘到容器的控制台执行:
mv /etc/apt/sources.list /etc/apt/sources.list.bak && \ echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list && \ echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list && \ echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list && \ echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
刷新get源
root@f49b15115297:/# apt-get update
下载软件 vim
root@f49b15115297:/# apt-get remoce vim -y
测试是否安装成功
root@f49b15115297:/# which vim /usr/bin/vim
卸载软件
root@f49b15115297:/# apt-get remove vim -y
其实就是把平时的yum命令换成了apt-get命令
每个容器也有自己的源地址,install安装 remove卸载
下面介绍一些常用命令的安装:
ping命令
apt-get install -y iputils-ping
ip -a , netstat 命令
apt-get install -y net-tools