- [Instructor] One of the genius ways
about how Docker was designed
is that the Docker images are made up of layers.
This layered file system allows Docker
to be really flexible and really efficient.
Now, how it works is that these images
have multiple read-only layers.
That's important because they're read-only,
they can't be modified.
You can build new images from existing images,
but you can't modify those existing images.
Multiple containers are typically based on the same image,
so you can use that image
and spawn hundreds or thousands of containers.
And as I said, you can even build new images
from existing images,
and that's something we'll be doing in this course.
Now, when an image is instantiated, or run,
as a container, a top writable layer is created.
And then that top writable layer
is actually deleted when the container is removed.
Docker accomplishes this using storage drivers
to manage the contents of the image layers
and that top writable layer.
Each storage driver handles this implementation
a little bit differently,
but all drivers use stackable image layers
and then a copy-on-write, or COW, strategy.
So, let's take a look at how this works.
The Docker image union file system, as it's called,
starts off at the bottom-most layer,
with what they call a manifest.
A manifest is, as you would expect,
just like a container manifest on a container ship.
This manifest is a document.
In this case, it's a little bit of code,
that describes what's inside the container.
So, we start off with this description of the container.
And then on top of that,
you have the first container layer.
For example, that might be an operating system,
like the Ubuntu operating system,
or Ubuntu Linux.
So, you're going to use that to create a new container.
So, you start off with the Ubunutu base image.
And then you add some configuration changes,
perhaps a host name or some other user
that you want to be defined on every container
that's going to be run, based on this image.
So, that again is a new layer
of the layered Docker file system.
It's a new layer of this image
that you're creating.
From there, perhaps you specify
to install an application, for example, an SSH server.
That application is yet another layer of this image
that we're creating.
And then perhaps there's some more changes on top of that.
The point here is that we're building
what kind of looks like a layered cake
and that is the Docker image union file system
that's used when creating a Docker image.
When you run that image and create a container
or instantiate a container, as it's called,
that top writable layer is created
and when you go into the container
and make changes to that container,
or perhaps the application runs
and modifies files inside the container,
that writable layer is modified.
When the container is stopped,
that writable layer remains,
however, if the container is removed,
the writable layer is gone or deleted.
And the image is the only thing that remains.
And this is why people say that containers are stateless.
So, that's how layering works with Docker images.
The Docker union file system starts off with a manifest,
from there it builds up multiple layers
as you make additional changes.
Additional changes, for example,
operating systems, configurations, and applications,
to the image as you're building that image.
But all those layers are read-only inside the image.
It's only when that image is instantiated
into a container that the top writable layer is created.