13
2022
12
17:13:28

Docker报错OCI runtime exec failed: exec failed: unable to start container process: exec: “/bin/bash“解决



推荐点击下面图片,通过本站淘宝优惠价购买:

image.png

报错

进入容器时,报如下错误:


[root@iZhp33j6fklnmhbf0lz2obZ admin]# docker exec -it admin_web_1 /bin/bash

OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown


解决

将 /bin/bash换成 /bin/sh成功


[root@iZhp33j6fklnmhbf0lz2obZ admin]# docker exec -it admin_web_1 /bin/sh

/code # ls

Dockerfile          app.py              bak                 docker-compose.yml  index.html


分析

制作镜像时使用了精简版,只装了sh命令,未安装bash。

如下都是精简版:


redis:alpine FROM

python:3.6-alpine


小拓展

Shell简介

Shell是一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务。Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 既是一种命令语言,又是一种程序设计语言。


sh(Bourne Shell)是一个早期的重要shell,1978年由史蒂夫·伯恩编写,并同Version 7 Unix一起发布。

bash(Bourne-Again Shell)是一个为GNU计划编写的Unix shell。1987年由布莱恩·福克斯创造。主要目标是与POSIX标准保持一致,同时兼顾对sh的兼容,是各种Linux发行版标准配置的Shell,在Linux系统上/bin/sh往往是指向/bin/bash的符号链接。


含义:


#! 是一个特殊标记,说明这是一个可执行的脚本。除了第一行,其他以#开头的都不再生效,为注释。

#! 后面是脚本的解释器程序路径。这个程序可以是shell,程序语言或者其他通用程序,常用的是bash、sh。


#!/bin/bash

#!/bin/sh


查看

查看系统可使用的shell类型


cat /etc/shells    


[root@iZhp33j6fklnmhbf0lz2obZ admin]#  cat /etc/shells

/bin/sh

/bin/bash

/usr/bin/sh

/usr/bin/bash


查看当前默认设置,一般在第一行


cat /etc/passwd    

1

[root@iZhp33j6fklnmhbf0lz2obZ admin]# cat /etc/passwd

root:x:0:0:root:/root:/bin/bash


查看当前sh状态


ll /bin/sh   


查看当前bash状态


ll /bin/bash  


[root@iZhp33j6fklnmhbf0lz2obZ admin]# ll /bin/sh

lrwxrwxrwx. 1 root root 4 Nov  9  2019 /bin/sh -> bash

[root@iZhp33j6fklnmhbf0lz2obZ admin]# ll /bin/bash

-rwxr-xr-x. 1 root root 1219248 Nov  9  2019 /bin/bash


sh与bash区别:

sh 遵循POSIX规范:“当某行代码出错时,不继续往下解释”。bash 就算出错,也会继续向下执行。


sh 脚本:


#!/bin/sh

source err

echo "hello"


bash 脚本:


#!/bin/bash

source err

echo "hello2"


输出结果:


[root@iZhp33j6fklnmhbf0lz2obZ admin]# bash hello2.sh 

hello2.sh: line 2: err: No such file or directory

hello2

[root@iZhp33j6fklnmhbf0lz2obZ admin]# sh hello.sh 

hello.sh: line 2: source: err: file not found

[root@iZhp33j6fklnmhbf0lz2obZ admin]# bash --posix hello2.sh 

hello2.sh: line 2: source: err: file not found



小结

sh 跟bash的区别是bash是否开启POSIX模式。

sh是bash的一种特殊的模式,sh就是开启了POSIX标准的bash, /bin/sh 相当于 /bin/bash --posix。

在Linux系统上/bin/sh往往是指向/bin/bash的符号链接

————————————————


本文链接:http://www.hqyman.cn/post/3331.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:





休息一下,本站随机推荐观看栏目:


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

您的IP地址是: