Re:Linux containers in 500 lines of code (2016)
by arpa on Tuesday February 04, 2020 @03:15PM
(#22240421)
Docker in ~100 lines of bash: https://github.com/p8952/bocker
[ Parent
| on HN ]
Re:Linux containers in 500 lines of code (2016)
by VWWHFSfQ on Tuesday February 04, 2020 @03:44PM
(#22240742)
"100 lines of bash" is pretty generous. they might as well have just made it 1 line of bash with the way the code is written
Re:Linux containers in 500 lines of code (2016)
by SahAssar on Tuesday February 04, 2020 @04:23PM
(#22241136)
That's not fair considering the two longest lines are for logging into dockerhub and parsing input arguments.
Re:Linux containers in 500 lines of code (2016)
by _zer0 on Tuesday February 04, 2020 @03:57PM
(#22240876)
Only the first few lines of the script look dense. Everything else looks normal to me.
Re:Linux containers in 500 lines of code (2016)
by fwip on Tuesday February 04, 2020 @04:25PM
(#22241155)
Stuff like https://github.com/p8952/bocker/blob/master/bocker#L94 is super dense.
I might write that something like:
cid="$(
ps o ppid,pid |
grep "^$(
ps o pid,cmd |
grep -E "^\ *[0-9]+ unshare.*$1" |
awk '{print $1}'
)" |
awk '{print $2}'
)"
Re:Linux containers in 500 lines of code (2016)
by travbrack on Tuesday February 04, 2020 @09:32PM
(#22243478)
Maybe I've spent too much time writing one-liners in bash but I really prefer the original to yours. I can read the original much faster because it matches the pattern for how I write bash on the command line. Yours looks totally foreign to how bash is normally written. Not saying one is better than the other, just my personal preference.
Re:Linux containers in 500 lines of code (2016)
by stingraycharles on Tuesday February 04, 2020 @04:41PM
(#22241298)
I agree with you that their code is fairly dense, yours is overly verbose.
Having said that, looking at their code, I don’t get the impression they’re optimizing for LOC. There is plenty of verbosity and opportunity to remove lines of code if they wanted.
Re:Linux containers in 500 lines of code (2016)
by cyansmoker on Tuesday February 04, 2020 @06:52PM
(#22242470)
Can confirm. The bocker code (incl. my modest contributions) was targeted towards showing that the Linux toolbox was available and scriptable.
Re:Linux containers in 500 lines of code (2016)
by fwip on Wednesday February 05, 2020 @12:47PM
(#22249235)
Dang, didn't expect the downvotes for sharing my bash coding style. :(
Re:Linux containers in 500 lines of code (2016)
by Hello71 on Tuesday February 04, 2020 @04:33PM
(#22241218)
or maybe even cid=$(pgrep -P $(pgrep -f "unshare.*$1")).
Re:Linux containers in 500 lines of code (2016)
by lproven on Friday February 07, 2020 @08:08AM
(#22265581)
Exactly... I mentioned this in an article 4 years ago.
https://www.theregister.co.uk/2016/07/05/containers_state_of...