前言
有時候在docker容器里面不僅沒有你期望的那些常用的命令,甚至沒有yum
命令讓你去安裝那些常用的命令。
root@50fb890c1f35:/# yum
bash: yum: command not found
無yum
原因
- 一些
docker
容器內(nèi)是沒有這些應(yīng)用的,需要我們自己安裝的 - 這個容器的系統(tǒng)很可能不是
Centos
系而是Ubuntu
或者其他操作系統(tǒng),你可以通過命令cat /proc/version
查看是否是烏班圖系統(tǒng)
系統(tǒng)類別
Linux系統(tǒng)主要有2種分類,常見的有RedHat
、Debian
:
- RedHat系列:Redhat、Centos、Fedora
- Debian系列:Debian、Ubuntu
軟件包管理工具
- yum:屬于Redhat、Centos系的軟件包管理工具
- apt:屬于Debian、Ubuntu系的軟件包管理工具
解決辦法
更新apt源之前,建議添加阿里云源:
# 修改 apt-get 源的配置文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #備份
sudo vim /etc/apt/sources.list #修改
sudo apt-get update #更新列表
阿里云源
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
更新命令
# 更新apt源
apt-get update
# 使用apt安裝yum
apt-get install yum
示例
bash: yum: command not found
apt-get update && apt-get install yum
如果有其它命令缺失,可直接使用apt包進行安裝,示例如下:
bash: ip: command not found
apt-get update && apt-get install -y iproute2
bash: ping: command not found
apt-get update && apt install iputils-ping
bash: ifconfig: command not found
apt-get update && apt install net-tools
bash: vi: command not found
apt-get update && apt-get install vim
bash: route: command not found
apt-get update && apt-get install -y iproute2 && apt-get update && apt install net-tools
bash: netstat: command not found
apt-get update && apt install net-tools
bash: ps: command not found文章來源:http://www.zghlxwxcb.cn/news/detail-802271.html
apt-get update && apt-get install procps
bash: top: command not found文章來源地址http://www.zghlxwxcb.cn/news/detail-802271.html
apt-get update && apt-get install procps
到了這里,關(guān)于解決Docker容器沒有yum命令的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!