OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "ip": executable file not found in $PATH: unknown
我们下载的某个镜像(例如tomcat镜像)是精简版的,利用这个镜像去打开一个容器的时候发现没有ip addr这个命令。
# 进入容器内部(比如tomcat01容器)docker exec -it --name tomcat01 -P tomcat:9.0 /bin/bashapt install -y iproute2注意:查看一下容器的系统版本信息:
cat /etc/os-release★ Linux系统分为两种:
1.RedHat系列:Redhat、Centos、Fedora等
2.Debian系列:Debian、Ubuntu等
RedHat系列的包管理工具是yum
Debian系列的包管理工具是apt-get
● 查看系统版本命令:cat /etc/os-release
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package iproute2
包管理工具apt的镜像是国外的导致,下载速度过慢导致的。
# 进入配置文件cd /etc/apt# 查看目录信息lscat sources.list# 备份mkdir cat sources.list.backupcp sources.list ./sources.list.backupcd ../# 以覆盖+追加的方式替换掉sources.list文件echo 'deb https://mirrors.aliyun.com/debian bullseye main'>sources.listecho 'deb https://mirrors.aliyun.com/debian-security bullseye-security main'>>sources.listecho 'deb https://mirrors.aliyun.com/debian bullseye-updates main'>>sources.list# 执行一下更新命令:apt-get update -y# 执行下载 iproute2命令:apt install -y iproute2# 测试1:-it 与容器进行交换docker exec -it --name tomcat01 -P tomcat:9.0 ip addr# 测试2:先进入容器,然后测试ip命令docker exec -it --name tomcat01 -P tomcat:9.0 /bin/baship a以下,是我,搜索本问题时,被误导产生的一些无效折腾
OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "ip": executable file not found in $PATH: unknown
报错原因:我们下载的Tomcat镜像是精简版的,利用这个镜像去打开一个容器的时候发现没有ip addr这个命令。
解决方式:安装 iproute2:apt install -y iproute2
● 又错误:
-bash: apt: command not found
问题原因:linux的版本造成的,我这个版本使用的是yum,而不是apt
解决:yum install -y iproute2
● 又错误:No package iproute2 available. Error: Nothing to do
★ 解决方式1:安装yum的扩展包epel-release
查看linux版本,下载对应版本的epel-release
# 查看系统的命令:cat /etc/redhat-release● 又错误:安装epel-release报错
执行命令 yum -y install https://mirrors.aliyun.com/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm
报错:
Loaded plugins: fastestmirror
epel-release-7-14.noarch.rpm | 15 kB 00:00:00
Examining /var/tmp/yum-root-OIjg1L/epel-release-7-14.noarch.rpm: epel-release-7-14.noarch
/var/tmp/yum-root-OIjg1L/epel-release-7-14.noarch.rpm: does not update installed package.
Error: Nothing to do解决:先使用wget 命令下载,然后再执行yum 命令安装
# 查看 epel 版本信息命令:rpm -qa|grep epelepel-release-7-14.noarch# 卸载老版本的epel-release(若是最新版,这不用版本可以不写,我的刚好就是最新版本的,不然就需要写明卸载epel-release-某个版本)命令:yum remove epel-release 或者 yum remove epel-release-7-14.noarch# 安装 epel-release命令:yum install -y epel-release-7-14.noarch● 此时,安装iproute2,错误依旧:yum install -y iproute2
No package iproute2 available.
Error: Nothing to do---更换解决方式
★ 方式2:更新yum 源,记得先备份原先的yum源(结果依然无效)
# 进入目录cd /etc/yum.repos.d/# 备份:备份方式1:mkdir yum.repos.d.backupcp -r yum.repos.d ./yum.repos.d.backup备份方式2:mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup# 根据centos版本下载对应的新源【我的centos是版本7的】wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # 清空yum缓存yum clean all# 生成缓存,会把新下载CentOS-Base.repo源生效yum makecache # 更新yum -y update? 我明白了:No package iproute2 available.
Error: Nothing to do。
意思是,找不到可以利用的包(安装包),解决:就是先下载下来 iproute2的安装包,然再安装。
# 下载iproute2的安装包# 安装iproute2
本题解决方法,早已跑偏,还记得咱的问题是什么吗?
1、了解网络配置工具net-tools与iproute2,发现:net-tools 是老版本linux的网络工具,而iproute2是linux新版本(例如centos7、centos8)的网络工具,
且已经内置,不用手动安装。"至此,恍然大悟,跑题了,咱是docker 内部没有iproute2,而不是centos系统没有"。可以直接使用网络命令,例如ip addr 等等,查看iproute2的版本命令: ip -V
[root@iZwz9535z41cmgcpkm7i81Z ~]# ip -Vip utility, iproute2-ss1705012、iproute2的下载镜像:https://mirrors.edge.kernel.org/pub/linux/utils/net/iproute2/
★
Docker容器没有ip addr命令:exec ip addr 报错.
报错原因:我们下载的Tomcat镜像是精简版的,利用这个镜像去打开一个容器的时候发现没有ip这个命令。
解决方式:
[先解决安装yum 的问题,再通过yum 安装iproute2] (不对,通过查询docker 容器的系统版本,发现版本是debain,内置的是apt,不是yum)
安装 iproute2:apt install -y iproute2
(1)查看docker 容器的系统版本:cat /etc/os-release
# 系统版本root@f1cfb81dedfd:/usr/local/tomcat# cat /etc/os-releasePRETTY_NAME="Debian GNU/Linux 11 (bullseye)"NAME="Debian GNU/Linux"VERSION_ID="11"VERSION="11 (bullseye)"VERSION_CODENAME=bullseyeID=debianHOME_URL="https://www.debian.org/"SUPPORT_URL="https://www.debian.org/support"BUG_REPORT_URL="https://bugs.debian.org/"# 系统版本详情,redhat的命令:cat /etc/redhat-release debain的命令:cat /etc/debian_version(2)安装 iproute2:
root@f1cfb81dedfd:/usr/local/tomcat# apt install -y iproute2Reading package lists... DoneBuilding dependency tree... DoneReading state information... DoneE: Unable to locate package iproute2
问题:Unable to locate package:无法找到包。
解决:升级一下 apt,再安装 iproute2
apt update又报错:
18 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: Failed to fetch http://deb.debian.org/debian/dists/bullseye/InRelease Could not connect to debian.map.fastlydns.net:80 (151.101.74.132), connection timed out Could not connect to deb.debian.org:80 (151.101.110.132), connection timed out
W: Failed to fetch http://deb.debian.org/debian/dists/bullseye-updates/InRelease Unable to connect to deb.debian.org:http:
W: Some index files failed to download. They have been ignored, or old ones used instead.
如果本文对你有帮助的话记得给一乐点个赞哦,感谢!
本文来自博客园,作者:一乐乐,转载请注明原文链接:https://www.cnblogs.com/shan333/p/16196813.html