Improved detection of available shell in container (fixes #5)#15
Improved detection of available shell in container (fixes #5)#15jpetazzo merged 4 commits intojpetazzo:masterfrom
Conversation
There was a problem hiding this comment.
I think we might have to use "$@" because without the quotes it will break down the parameters... Not sure, but we should double-check first :-)
There was a problem hiding this comment.
Yeah, I first had the whole "@NSENTER...... line in both branches, once with "$@" and once with $COMMAND, but that was not very DRY.
I will check if I adding the quotes here works properly and update my PR. Thanks!
docker-enter tried to open the same shell inside the container as on the host, which failed if the container did not *have* that shell. Additionally, (environment) variables of the host were also present in the nsenter session. This change; 1. Checks if a command was given as parameter 2. If no command, check if ‘bash’ is present inside the container 3. Otherwise use ‘sh’ as shell As discussed here; https://github.com/jpetazzo/nsenter/issues/5
|
@jpetazzo Ok, added the quotes, seems to work correctly (fingers crossed :)). BTW, I was reading one of your older blogposts (http://jpetazzo.github.io/2014/03/23/lxc-attach-nsinit-nsenter-docker-0-9/); any reason you decided to use |
|
@JessThrysoee Looks good. But if I understood your comment here https://github.com/jpetazzo/nsenter/issues/5#issuecomment-50095177 correctly, |
|
@JessThrysoee was thinking along the line of; ototh, clearing the environment twice wouldn't hurt. LOL Probably, the |
|
Yes I also didn't think clearing the environment twice mattered. The But, |
|
$HOME should not be added to OPTS, at least not for the In fact the only reason to go with Because the bourne shell version of exec doesn't accept options, there is nothing gained by |
|
@JessThrysoee makes sense (you're a lot better than this than I am!). Just did a quick search and apparently, The Is it okay to use your suggestions in my PR? Or would you prefer to open your own PR? Feels like plagiarism 😺 @jpetazzo only thing I run into when using |
Added various improvements as suggested by @JessThrysoee - Use 'type' instead of 'which' - Added OPTS var to reduce duplicated code - Use 'exec -cl bash' for a 'clean' bash shell - Added HOME=/root for 'sh' shell
|
@thaJeztah No need for another PR :-) The "Cannot set tty..." seems to be a /bin/dash warning (the /bin/sh on most linux systems). The
|
|
@JessThrysoee clever! Love it! Maybe we should add some documentation inside the script to explain why I'll update the PR later and will think of documentation later |
More awesomeness by @JessThrysoee Now using su to; - Automatically log in to the default shell of the container - Set up the right environment variables (e.g. $PATH, $HOME) - No longer requiring to *detect* the default shell
|
Updated the PR. Haven squashed yet, in case more improvements come 😄 |
|
Looks good, but I have just one more tweak :-) I just read the su manpage and it says "clears all environment variables except for TERM". We really want to preserve TERM so here is yet another attempt: I also updated the comments with the information from the su manpage. |
|
@JessThrysoee I'll update the PR when I'm back at my computer. This has been very educational! Only thing I'm not sure about is "what" to mention as default command here |
|
How about? The docker manpages just use |
|
@JessThrysoee guess something like that would work, was too focused on keeping it a single line (as it was now) but, that's nonsense. Guess it's getting late :) Will update the PR in the morning, and clean up the commits if all things are ready. Saw that quite a lot of work is in progress for implementing |
- Don’t clear TERM environment-variable when using su. - Updated usage description
|
ping @jpetazzo I think the new docker-enter has come quite a long way (the heavy lifting has been done by @JessThrysoee) Do you want them rebased? |
|
Thanks! You're the best, all of you :-) I'm happy to merge this. And sorry for the delay; I was at OSCON the whole week, and couldn't check GitHub notifications as much as I wanted! |
Improved detection of available shell in container (fixes #5)
|
@jpetazzo no problem at all, due to your delay we were able to come up with a better version! ....just in time before docker RunIn() is implemented LOL |
docker-enter tried to open the same shell inside the container as on
the host, which failed if the container did not have that shell.
Additionally, (environment) variables of the host were also present in
the nsenter session.
This change;
As discussed here; https://github.com/jpetazzo/nsenter/issues/5