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

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

CC BY-SA 3.0
2017-12-08T08:54:52.943Z
2017-12-08T08:54:52.943Z
AnoE
<h1><code>chroot</code> is not a security measure</h1>
<p>Though some people mistakenly think it is, it isn't. From <code>man 2 chroot</code>,</p>
<blockquote>
<p>This call <strong>changes an ingredient in the pathname resolution process and does nothing else.</strong> 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, <code>chroot()</code> has been used by daemons to restrict themselves prior to passing paths supplied by untrusted users to system calls such as <code>open(2)</code>.  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 <code>chdir(2)</code> to the to-be-moved directory, wait for it to be moved out, then open a path like ../../../etc/passwd.</p>
<p>A slightly trickier variation also works under some circumstances if chdir(2) is not permitted.  If a daemon allows a &quot;chroot directory&quot;  to  be  specified,  that usually means that if you want to prevent remote users from accessing files outside the <code>chroot</code> directory, you must ensure that folders are never moved out of it.</p>
<p>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 &quot;chroot jail&quot; by doing:</p>
<pre><code>mkdir foo; chroot foo; cd ..
</code></pre>
<p>This call does not close open file descriptors, and such file descriptors may allow access to files outside the chroot tree.</p>
</blockquote>
<h1>Namespaces</h1>
<p>Namespaces are a security feature. Whereas chroot does not provide file system isolation, namespaces do precisely that.</p>

CC BY-SA 4.0
2022-05-19T04:08:44.493Z
2022-05-19T04:08:44.493Z
Evan Carroll
<p>Well, the extra bells and whistles is called process isolation, a container gets its own <a href="https://en.wikipedia.org/wiki/Linux_namespaces" rel="noreferrer">namespace</a> from the host kernel, that means the program in the container can't try to read kernel memory or eat more RAM than allowed.</p>

<p>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.</p>

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

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

CC BY-SA 3.0
2017-12-08T17:30:31.857Z
Note that `aufs` is not used by default anymore. Now it's `overlay2`
Vitalii Vitrenko
CC BY-SA 3.0
2017-12-08T19:16:59.733Z
True, but I think there's more educational materials referencing aufs than overlay2 for now :)
Tensibai
CC BY-SA 3.0
2017-12-10T17:07:58.800Z
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
CC BY-SA 3.0
2017-12-10T19:08:39.743Z
@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
CC BY-SA 4.0
2017-12-08T08:44:27.413Z
2019-11-17T16:36:09.933Z
2019-11-17T16:36:09.933Z
Tensibai
<p>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.</p>

<p>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.</p>

<p>I couldn't find this <a href="https://stackoverflow.com/questions/46450341/chroot-vs-docker">Chroot Vs Docker</a> clear enough either.</p>

CC BY-SA 3.0
2017-12-08T21:28:29.277Z
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
<docker><linux><containers>
Difference between chroot and Docker
Vipin Menon
# Difference between chroot and Docker

(Asked by: username_0 on 2017-12-08)

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](https://stackoverflow.com/questions/46450341/chroot-vs-docker) clear enough either.

**Tags:** docker, linux, containers

> **Comments:**
> **username_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.  

---

## 3 answers

### Answer by username_4 on 2017-12-08. Score: 14

Well, the extra bells and whistles is called process isolation, a container gets its own [namespace](https://en.wikipedia.org/wiki/Linux_namespaces) 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.

> **Comments:**
> **username_5**: Note that `aufs` is not used by default anymore. Now it's `overlay2`  
> **username_4**: True, but I think there's more educational materials referencing aufs than overlay2 for now :)  
> **username_1**: 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...  
> **username_4**: @username_1 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.  

---

### Answer by username_2 on 2017-12-08. Score: 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.).


---

### Answer by username_3 on 2022-05-19. Score: 2

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.


---

