報錯
進入容器時,報如下錯誤
dockeruser@dell-PowerEdge-R740:~$ docker exec -it daf2 /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
dockeruser@dell-PowerEdge-R740:~$ docker exec -it daf2 /bin/sh
分析
制作鏡像時使用了精簡版,只裝了sh命令,未安裝bash。
拓展
(1)shell簡介
Shell是一種應(yīng)用程序,該應(yīng)用程序提供了一個界面,用戶通過這個界面訪問操作系統(tǒng)內(nèi)核的服務(wù)。Shell 是一個用 C 語言編寫的程序,是用戶使用 Linux 的橋梁。Shell 既是一種命令語言,又是一種程序設(shè)計語言。
sh(Bourne Shell)是一個早期的重要shell,1978年由史蒂夫·伯恩編寫,并同Version 7 Unix一起發(fā)布。
bash(Bourne-Again Shell)是一個為GNU計劃編寫的Unix shell。1987年由布萊恩·福克斯創(chuàng)造。主要目標是與POSIX標準保持一致,同時兼顧對sh的兼容,是各種Linux發(fā)行版標準配置的Shell,在Linux系統(tǒng)上/bin/sh往往是指向/bin/bash的符號鏈接。
(2)#!
- #!?是一個特殊標記,說明這是一個可執(zhí)行的腳本。除了第一行,其他以#開頭的都不再生效,為注釋。
- #!?后面是腳本的解釋器程序路徑。這個程序可以是shell,程序語言或者其他通用程序,常用的是bash、sh。
(3)sh與bash區(qū)別
- sh 跟bash的區(qū)別是bash是否開啟POSIX模式。
- sh是bash的一種特殊的模式,sh就是開啟了POSIX標準的bash, /bin/sh 相當于 /bin/bash --posix。
- 在Linux系統(tǒng)上/bin/sh往往是指向/bin/bash的符號鏈接
ln -s /bin/bash /bin/sh
- sh 遵循POSIX規(guī)范:“當某行代碼出錯時,不繼續(xù)往下解釋”。bash 就算出錯,也會繼續(xù)向下執(zhí)行。
hello.sh腳本:
#!/bin/sh
source err
echo "sh hello"
hello2.sh腳本:文章來源:http://www.zghlxwxcb.cn/news/detail-844641.html
#!/bin/bash
source err
echo "bash hello2"
輸出結(jié)果:文章來源地址http://www.zghlxwxcb.cn/news/detail-844641.html
[root@admin]# bash hello2.sh
hello2.sh: line 2: err: No such file or directory
hello2
[root@admin]# sh hello.sh
hello.sh: line 2: source: err: file not found
[root@admin]# bash --posix hello2.sh
hello2.sh: line 2: source: err: file not found
到了這里,關(guān)于10.docker exec -it /bin/bash報錯解決、sh與bash區(qū)別的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!