解决Docker容器没有yum命令

20 篇文章 6 订阅
当在Docker容器中发现缺少yum或其他常用命令时,可以通过检查系统类型(如使用`cat/proc/version`)来确认。对于非Centos系统,如Ubuntu,应使用apt作为软件包管理工具。文章建议将apt源更新为阿里云源,并通过`apt-getinstall`命令安装yum和其他缺失的命令,如iproute2、net-tools和vim等。
摘要由CSDN通过智能技术生成

前言


有时候在docker容器里面不仅没有你期望的那些常用的命令,甚至没有yum命令让你去安装那些常用的命令。

root@50fb890c1f35:/# yum
bash: yum: command not found

yum原因

  • 一些docker容器内是没有这些应用的,需要我们自己安装的
  • 这个容器的系统很可能不是Centos系而是Ubuntu或者其他操作系统,你可以通过命令cat /proc/version查看是否是乌班图系统

系统类别

Linux系统主要有2种分类,常见的有RedHatDebian

  • 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
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

花伤情犹在

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值