News for hackers. Stuff that matters.
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
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...

Re:Linux containers in 500 lines of code (2016) by musicale on Tuesday February 04, 2020 @08:05PM (#22243022)
Linux containers aren't rocket science, but the system call API is confusing and hard to get right (I find pid namespaces particularly annoying), the basic user commands (unshare, ip netns...) are kind of a pain to use, and orchestration using Docker/Kubernetes is overly complex and opaque. There is clearly room for improvement at all levels.
Re:Linux containers in 500 lines of code (2016) by dang on Tuesday February 04, 2020 @02:52PM (#22240164)
Re:Linux containers in 500 lines of code (2016) by sascha_sl on Tuesday February 04, 2020 @05:35PM (#22241841)
Liz Rice has done some awesome on-stage live coding, including a very small container runtime in go.

https://www.youtube.com/watch?v=8fi7uSYlOdc

Re:Linux containers in 500 lines of code (2016) by markandrewj on Tuesday February 04, 2020 @06:13PM (#22242186)
She has an O'Reilly video course on building container runtime's in go that is really great as well.
Re:Linux containers in 500 lines of code (2016) by kristianp on Tuesday February 04, 2020 @11:24PM (#22244000)
I'm wondering if MacOS has the requisite system calls to have its own native containers, I imagine it does, Darwin being based on BSD. Are there any products that use that functionality?
Re:Linux containers in 500 lines of code (2016) by justincormack on Wednesday February 05, 2020 @03:16AM (#22244919)
Kind of but with limitations. You have chroot, which may or may not be secure, app sandbox which is quite powerful (but best used without chroot). No process namespaces or jails, very limited network isolation. No bind mounts. Overall very limited, you could do something but it woild be quite different.
Re:Linux containers in 500 lines of code (2016) by ailideex on Wednesday February 05, 2020 @01:07AM (#22244404)
Not sure how you get from Darwin being based on BSD to Darwin should be able to support something which heavily relies on Linux specific functionality to the point where even Freebsd having trouble https://wiki.freebsd.org/Docker

Sure with enough changes MacOS could support it, but then with enough changes to anything, so that is not really a sensible measure.

Re:Linux containers in 500 lines of code (2016) by TheDong on Wednesday February 05, 2020 @01:24AM (#22244473)
The question wasn't about running docker on *BSD or macOS, but rather running some form of native container. Native containers don't rely on linux, they rely on the kernel having some form of containerization primitive.

FreeBSD has jails, which are a native type of container on freebsd.

However, BSD operating systems are really different from each other. OpenBSD doesn't have jails or anything too like containers, and macOS does have sandboxes (which are kinda like a container in some way), but no proper containers.

Docker isn't really related to the question of whether a native container solution exists on non-linux platforms.

Re:Linux containers in 500 lines of code (2016) by jsjohnst on Wednesday February 05, 2020 @09:27AM (#22246891)
Darwin is the generic name for the open source posix OS that’s the basis for MacOS (and others).

It would be more appropriate to compare the XNU micro kernel used in Darwin to the Linux kernel used in GNU/Linux in your analogy.

Re:Linux containers in 500 lines of code (2016) by pjmlp on Wednesday February 05, 2020 @01:47AM (#22244577)
Re:Linux containers in 500 lines of code (2016) by kazinator on Wednesday February 05, 2020 @12:18PM (#22248912)
> pivot_root is a system call lets us swap the mount at / with another. Glibc doesn't provide a wrapper for it, but includes a prototype in the man page. I don't really understand, but OK, we'll include our own.

Probably because pivot_root is a speciality that is used in initramfs boostrapping and is exposed to that scriptology via the pivot_root program that comes from the util-linux project.

Re:Linux containers in 500 lines of code (2016) by exxo_ on Wednesday February 05, 2020 @12:02AM (#22244177)
Re:Linux containers in 500 lines of code (2016) by projektfu on Tuesday February 04, 2020 @03:53PM (#22240832)
I like the use of noweb. Very slick.
Re:Linux containers in 500 lines of code (2016) by parhamn on Tuesday February 04, 2020 @05:27PM (#22241757)
I was actually wondering what the lowest-resource way of launching a bunch of mostly-idle single port applications in isolation currently is. Docker runtime is bloated, Kubernetes has recommended limits (and enforced on cloud providers), Runc feels like you have to implement Kubernetes/Docker on top yourself. Anyone seen anything else out there to run a few thousand single port binaries and multiplex them with a webserver?
Re:Linux containers in 500 lines of code (2016) by oszione on Tuesday February 04, 2020 @06:14PM (#22242195)
Podman with the new crun[1] container runtime is pretty lightweight. Everything circles back to C.

[1]: https://github.com/containers/crun

Re:Linux containers in 500 lines of code (2016) by xnyan on Tuesday February 04, 2020 @05:58PM (#22242048)
I’ve had really good results with LXC/LXD. Depending on the privileges of the container the only area of overhead that sometimes concerns me is filesystem IO, but ive been able to work around it.
Re:Linux containers in 500 lines of code (2016) by dpc_pw on Tuesday February 04, 2020 @08:38PM (#22243198)
Under the hood docker uses `runc` which is fairly small and easy to use, IMO.