当前位置首页 > Linux知识

OCIruntimeexecfailed:execfailed:container_linux.go:380:startingc

阅读次数:878 次  来源:admin  发布时间:

一、报错 1、报错信息1:

OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "ip": executable file not found in $PATH: unknow

2、报错原因:

我们下载的某个镜像(例如tomcat镜像)是精简版的,利用这个镜像去打开一个容器的时候发现没有ip addr这个命令。

3、解决报错1的方法:安装工具 iproute2

# 进入容器内部(比如tomcat01容器)
docker exec -it --name tomcat01 -P tomcat:9.0 /bin/bash
apt 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

二、又报错: 1、报错信息2:

Reading package lists... Done

Building dependency tree... Done

Reading state information... Done

E: Unable to locate package iproute2

2、报错原因:

包管理工具apt的镜像是国外的导致,下载速度过慢导致的。

3、解决报错2的方法:更换apt 配置文件中的镜像

# 进入配置文件
cd /etc/apt
# 查看目录信息
ls
cat sources.list
# 备份
mkdir cat sources.list.backup
cp sources.list ./sources.list.backup
cd ../
# 以覆盖+追加的方式替换掉sources.list文件
echo 'deb https://mirrors.aliyun.com/debian bullseye main'>sources.list
echo 'deb https://mirrors.aliyun.com/debian-security bullseye-security main'>>sources.list
echo 'deb https://mirrors.aliyun.com/debian bullseye-updates main'>>sources.list
# 执行一下更新命令:
apt-get update -y
# 执行下载 iproute2命令:
apt install -y iproute2

三、问题解决,测试一下,在docker 容器内使用ip 命令

# 测试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/bash
ip a

以下,是我,搜索本问题时,被误导产生的一些无效折腾

■ 被误导在centos7(我的宿主机)中安装 iproute2,实则是centos新版版(比如centso7/centos8早已内置网络工具iproute2) ■ 然后又为了解决Docker容器没有ip addr命令,在宿主机安装 epel-release,结果报错,没有找到这个包,是因为网上的解决方案,命令不全,没有先执行下载 epel-release安装包,就直接来个yum install,导致找不到包。 ■ 同样,对于 iproute2,也是没有给出下载命令,却直接来个安装命令yum install iproute2,导致找不到包iproute2。 ■ 最重要的是 centos新版本已经内置有了iproute2,没必要安装呀 ■ 最最最重要的是跑题了,咱需要考虑的是命令ip是在docker容器执行失败,而在宿主机执行正常!解决起点应该回到容器内安装网络工具 iproute2。因为下载的镜像是精简版的,默认不自带网络工具iproute2。

● Docker容器没有ip addr命令:exec ip addr 报错:

OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "ip": executable file not found in $PATH: unknow

报错原因:我们下载的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 epel
epel-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.backup
cp -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 -V
ip utility, iproute2-ss170501

2、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-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_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 iproute2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: 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.

如果本文对你有帮助的话记得给一乐点个赞哦,感谢!

上一篇:(整理)linux常用命令及设置-备查(ubuntu10.10)(mini6410)(命令)(设置)(入门)-liu_xf
下一篇:Linux网络流量相关