1. 背景及原因
Docker中安装容器后,进入容器内,想要执行一些命令,却发现根本没有这个命令。
Docker容器都是最小化的Linux,所以有很多命令没有。
2. 解决
进入容器内
docker exec -it container_name bash
安装vi编辑器
apt-get install vim
如果过程中提示如下问题:
# apt-get install vim
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package vim
可以使用 apt-get update 更新apt-get
解决vi编辑器鼠标右键无法粘贴的问题
vi ~/.vimrc
# 输入以下内容,保存后即可
if has('mouse')
set mouse-=a
endif
更换国内源(要不然下载太慢了)
备份
mv /etc/apt/sources.list /etc/apt/source.list.bak 编辑
vi /etc/apt/sources.list
添加以下内容
deb mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
3.保存后更新
apt-get update
4.安装ps命令
apt-get install procps