# Understanding Layers in Docker Engine

**URL:** <https://forums.docker.com/t/understanding-layers-in-docker-engine/7595>\
**Category:** General\
**Created:** [March 17, 2016, 11:29pm UTC](https://forums.docker.com/t/understanding-layers-in-docker-engine/7595 "2016-03-17T23:29:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcrockett](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/tcrockett/32/5555_2.png) [@tcrockett](https://forums.docker.com/u/tcrockett)\
**Post date:** [March 17, 2016, 11:29pm UTC](https://forums.docker.com/t/understanding-layers-in-docker-engine/7595/1 "2016-03-17T23:29:08Z")

</div>

I’m having trouble getting my head wrapped around this…

If I have a Docker Engine running in Ubuntu and then I build a Dockerfile with something like this:

> FROM centos

> RUN yum -y update && yum -y install   
> apache

What exactly is going to happen here? Is it going to build a centos layer(s) that essentially contains diffs between the centos base and Ubuntu where the Engine is running? And then another layer(s) for the Apache package install?

Even though this works, would this be frowned upon…or not really since the objective is a Docker image should run in any Docker engine, regardless of the base Linux OS?

---

<div class="post-metadata">

**Author:** ![gtyler](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@gtyler](https://forums.docker.com/u/gtyler)\
**Post date:** [March 24, 2016, 5:06pm UTC](https://forums.docker.com/t/understanding-layers-in-docker-engine/7595/2 "2016-03-24T17:06:54Z")

</div>

Containers are isolated from the host operating system and its filesystem. The “centos” image provides the basis for the image that you’re building there, so the container filesystem will only have the files from the centos image and whatever changes you make in your Dockerfile.

---

<div class="post-metadata">

**Author:** ![tcrockett](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/tcrockett/32/5555_2.png) [@tcrockett](https://forums.docker.com/u/tcrockett)\
**Post date:** [March 24, 2016, 9:20pm UTC](https://forums.docker.com/t/understanding-layers-in-docker-engine/7595/3 "2016-03-24T21:20:33Z")

</div>

OK, so essentially all the files and layout defined in the centos image plus (in this case) all the files defined in the apache package. But the kernel in this case is still Ubuntu, correct? So all system calls, file i/o, etc. are ultimately performed by the OS hosting the Docker engine, right?

---

<div class="post-metadata">

**Author:** ![gtyler](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@gtyler](https://forums.docker.com/u/gtyler)\
**Post date:** [March 29, 2016, 1:06pm UTC](https://forums.docker.com/t/understanding-layers-in-docker-engine/7595/4 "2016-03-29T13:06:22Z")

</div>

Correct. This is the underlying technology used by Docker (all other similar products): [https://en.wikipedia.org/wiki/LXC](https://en.wikipedia.org/wiki/LXC)

---

<div class="post-metadata">

**Author:** ![dvohra](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/dvohra/32/5429_2.png) [@dvohra](https://forums.docker.com/u/dvohra)\
**Post date:** [April 19, 2016, 6:00pm UTC](https://forums.docker.com/t/understanding-layers-in-docker-engine/7595/5 "2016-04-19T18:00:02Z")

</div>

> [@tcrockett](#):
>
> But the kernel in this case is still Ubuntu, correct? So all system calls, file i/o, etc. are ultimately performed by the OS hosting the Docker engine, right?

_But the kernel in this case is still Ubuntu, correct? So all system calls, file i/o, etc. are ultimately performed by the OS hosting the Docker engine, right?_

Yes, but not the complete kernel is used for a Docker container. Only a lightweight snapshot (encapsulation) of the kernel is used for each of the several containers running on a host. The host does not directly perform system calls, file i/o, but each container has its own filesystem and networking.

---

<div class="post-metadata">

**Author:** ![tcrockett](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/tcrockett/32/5555_2.png) [@tcrockett](https://forums.docker.com/u/tcrockett)\
**Post date:** [April 19, 2016, 7:50pm UTC](https://forums.docker.com/t/understanding-layers-in-docker-engine/7595/6 "2016-04-19T19:50:54Z")

</div>

Ahhh…that is a great distinction, thank you. I didn’t realize each container had its own encapsulated kernel. Is there any documentation that talks about this more in depth?

---

<div class="post-metadata">

**Author:** ![dvohra](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/dvohra/32/5429_2.png) [@dvohra](https://forums.docker.com/u/dvohra)\
**Post date:** [April 19, 2016, 9:56pm UTC](https://forums.docker.com/t/understanding-layers-in-docker-engine/7595/7 "2016-04-19T21:56:02Z")

</div>

"Containers include the application and all of its dependencies, but share the kernel with other containers. They run as an isolated process in userspace on the host operating system. "

Refer Containers sub-section in _How is this different from virtual machines?_

> **[What is Docker?](https://www.docker.com/what-docker)**
>
> Docker is an open platform to build, ship and run distributed applications anywhere.
