简体   繁体   English

docker ubuntu容器:链接到bash的shell仍然启动shell

[英]docker ubuntu container: shell linked to bash still starts shell

Alright guys, so I try to install rvm in a docker container based on ubuntu:14.04. 好吧,伙计们,所以我尝试在基于ubuntu:14.04的docker容器中安装rvm。 During the process, I discovered that some people do something like this to ensure docker commands are also run with the bash: 在这个过程中,我发现有些人做了这样的事情,以确保docker命令也与bash一起运行:

RUN ln -fs /bin/bash /bin/sh

Now The weirdness happens and I hope someone of you can explain it to me: 现在奇怪的事情发生了,我希望你们中的某个人可以向我解释:

→ docker run -it --rm d81ff50de1ce /bin/bash
root@e93a877ab3dc:/# ls -lah /bin
....
lrwxrwxrwx  1 root root    9 Mar  1 16:15 sh -> /bin/bash
lrwxrwxrwx  1 root root    9 Mar  1 16:15 sh.distrib -> /bin/bash
...
root@e93a877ab3dc:/# /bin/sh
sh-4.3# echo $0
/bin/sh

Can someone explain what's going on here? 有人能解释一下这里发生了什么吗? I know I could just prefix my commands in the dockerfile w/ bash -c , but I would like to understand what is happening here and if possible still ditch the bash -c prefix in the dockerfile. 我知道我可以在dockerfile w / bash -c我的命令前缀,但是我想了解这里发生了什么,如果可能的话,仍然会抛弃dockerfile中的bash -c前缀。

Thanks a lot, Robin 非常感谢,罗宾

It's because bash has a compatibility mode where it tries to emulate sh if it is started via the name sh , as the manpage says: 这是因为bash有一个兼容模式,它试图模拟sh如果它是通过名称sh启动的,如手册页所示:

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. 如果使用名称sh调用bash,它会尝试尽可能接近地模仿sh的历史版本的启动行为,同时也符合POSIX标准。 When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order. 当作为交互式登录shell或带有--login选项的非交互式shell调用时,它首先尝试按顺序从/ etc / profile和〜/ .profile中读取和执行命令。 The --noprofile option may be used to inhibit this behavior. --noprofile选项可用于禁止此行为。 When invoked as an interactive shell with the name sh, bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. 当作为具有名称sh的交互式shell调用时,bash查找变量ENV,如果已定义则展开其值,并使用扩展值作为要读取和执行的文件的名称。 Since a shell invoked as sh does not attempt to read and execute commands from any other startup files, the --rcfile option has no effect. 由于以sh调用的shell不会尝试从任何其他启动文件读取和执行命令,因此--rcfile选项无效。 A non-interactive shell invoked with the name sh does not attempt to read any other startup files. 使用名称sh调用的非交互式shell不会尝试读取任何其他启动文件。 When invoked as sh, bash enters posix mode after the startup files are read. 当调用为sh时,bash在读取启动文件后进入posix模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM