25

I don't understand the difference between docker and chroot. Yes its nice in terms of the packaging the registry. But somehow I get the feeling its just chroot with extra bells and whistles.

I know I'm missing something. It'd would be great to know how they are different and the need of docker if chroot could do something similar.

I couldn't find this Chroot Vs Docker clear enough either.

1
  • Well, yes, Docker doesn't do anything that the kernel won't already do for you. It just packages it into a more-or-less coherent and fairly easy to use tool. You could make your own Docker if you could be bothered to do chroot, namespaces, quotas, NAT, and all the rest yourself.
    – Gaius
    Dec 8, 2017 at 21:28

3 Answers 3

13

Well, the extra bells and whistles is called process isolation, a container gets its own namespace from the host kernel, that means the program in the container can't try to read kernel memory or eat more RAM than allowed.

It also isolate network stacks, so two process can listen on port 8080 for exemple, you'll have to handle the routing at host level, there's no magic here, but this allow handling the routing at one place and avoid modifying the process configuration to listen to a free port.

Secondly a chroot is still read/write, any change is permanent, a docker container using aufs will start from a clean filesystem each time you launch the container (changes are kept if you stop/start it IIRC).

So while a container may be thought of as process namespace + chroot, the reality is a little more complex.

4
  • 1
    Note that aufs is not used by default anymore. Now it's overlay2 Dec 8, 2017 at 17:30
  • True, but I think there's more educational materials referencing aufs than overlay2 for now :)
    – Tensibai
    Dec 8, 2017 at 19:16
  • A normal process can't read any memory it's not supposed to either. If you are relying on Docker for security you're doing it wrong...
    – Gaius
    Dec 10, 2017 at 17:07
  • @Gaius you're reading me wrong, I'm just trying to give search clues to the OP... Adding docker in a delivery pipeline with all the freedom it give to developer to what they use inside is absolutely not a security point. Nonetheless namespaces protect from a bunch of stack overflow and buffer overflow by nature.
    – Tensibai
    Dec 10, 2017 at 19:08
8

Yes, there absolutely is more to it than chroot to the point that they have little to nothing in common.

  • A standardized script file format including semantics relating to the task a hand
  • Images (including anonymous in-between images), caching, naming, downloading etc. including powerful management (docker image prune ...)
  • Containers (including their own temporary file systems, naming, being able to docker exec into them etc.)
  • Process management (docker container ...)
  • Networking with just a simple option, including intra-docker-container-networking etc.
  • Volumes (including special managed volumes)
  • docker-compose or swarm as low-profile upgrades to much more.
  • The large zoo of other solutions based on dockerized containers (OpenShift etc.).
1

chroot is not a security measure

Though some people mistakenly think it is, it isn't. From man 2 chroot,

This call changes an ingredient in the pathname resolution process and does nothing else. In particular, it is not intended to be used for any kind of security purpose, neither to fully sandbox a process nor to restrict filesystem system calls. In the past, chroot() has been used by daemons to restrict themselves prior to passing paths supplied by untrusted users to system calls such as open(2). However, if a folder is moved out of the chroot directory, an attacker can exploit that to get out of the chroot directory as well. The easiest way to do that is to chdir(2) to the to-be-moved directory, wait for it to be moved out, then open a path like ../../../etc/passwd.

A slightly trickier variation also works under some circumstances if chdir(2) is not permitted. If a daemon allows a "chroot directory" to be specified, that usually means that if you want to prevent remote users from accessing files outside the chroot directory, you must ensure that folders are never moved out of it.

This call does not change the current working directory, so that after the call '.' can be outside the tree rooted at '/'. In particular, the superuser can escape from a "chroot jail" by doing:

mkdir foo; chroot foo; cd ..

This call does not close open file descriptors, and such file descriptors may allow access to files outside the chroot tree.

Namespaces

Namespaces are a security feature. Whereas chroot does not provide file system isolation, namespaces do precisely that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.