解决Docker容器没有yum命令
有时候在docker容器里面不仅没有你期望的那些常用的命令,甚至没有yum命令让你去安装那些常用的命令。无yum原因一些docker容器内是没有这些应用的,需要我们自己安装的这个容器的系统很可能不是Centos系而是Ubuntu或者其他操作系统,你可以通过命令查看是否是乌班图系统系统类别Linux系统主要有2种分类,常见的有RedHatDebianRedHat系列:Redhat、Centos、Fe
前言

有时候在docker容器里面不仅没有你期望的那些常用的命令,甚至没有yum命令让你去安装那些常用的命令。
root@50fb890c1f35:/# yum
bash: yum: command not found
无yum原因
- 一些
docker容器内是没有这些应用的,需要我们自己安装的 - 这个容器的系统很可能不是
Centos系而是Ubuntu或者其他操作系统,你可以通过命令cat /proc/version查看是否是乌班图系统
系统类别
Linux系统主要有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
apt-get update && apt-get install procps
bash: top: command not found
apt-get update && apt-get install procps
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)