In this video, we are going to explore storage drivers.
So storage drivers allow for writing data
in the writeable layer of the container.
And data written through this way
is not persistent and performance is not good.
The writeable layer is created when running any container,
and storage drivers handle
how the layers interact with one another.
For local use, the local driver,
the SSHFS drivers are available.
And for more enterprise-level use,
drivers are available through the Kubernetes
or Swarm orchestration layer.
You can select storage drivers yourself,
and different storage drivers are available for local use,
like aufs, overlay, overlay2,
btrfs,
zfs,
or devicemapper.
And every container stack
on the different distributions convert the wrong driver.
If you want to set a different driver,
you can set the driver in /etc/docker/daemon.json
Notice that this is a file that may not yet exist,
and if you want to set a driver,
you can put it in there in JSON format.
So you need the curly brackets,
the storage driver between double quotes, colon,
followed by the value that you want to use
for the storage driver.
When working with storage in Docker containers,
a CoW strategy is used.
That's copy-on-write.
If a container changes files in a lower layer,
the file is copied from the lower layer to the upper layer
and modified while it is there,
which is referred to as copy-on-write.
And using CoW strategy guarantees
that only modifications are stored
in the writeable file system layer,
and not everything.
And that is very storage efficient.
If multiple containers have started based on one image,
only the difference
between the container's writeable layers is stored.
And for write-intense applications,
this strategy however is not so efficient
and it is better to use external storage.
We'll explore that in upcoming videos,
but for now let's further explore CoW.
So I am going to run a demo for you.
And I'm just going to pop up the entire slide,
which is summarizing the demo,
which makes it easier for you to repeat
what I'm going to demonstrate.
So here's part one of my demo,
in which we are creating some Dockerfiles.
And here is part two,
in which we are going to use these Dockerfiles.
Let me run this demo for you.
So I will create a directory,
cow-test,
and let's go to that directory as well.
And from there, I'm creating a simple file,
simple shell script, hello.sh
This is a bare shell script
and it's just going to print hello.
In order to have it work, we need to make it executable,
which is a requirement for any file you want to run
as an executable on Linux.
And then we can create a Dockerfile.base
I'm using VIM on Dockerfile.base
And in there,
FROM
Ubuntu:20.04
COPY .to/app
Then I'm going to create Dockerfile.
And in Dockerfile, we are using FROM koe,
which happens to be Dutch for a cow.
Koe is not C-O-W by the way, with the animal, you know?
Base image 1.0
That's the base image that I still have to create
in CMD /app/hello.sh
Now we can build the base image.
So, docker build -t koe/baseimage:1.0
And we force the Dockerfile.base to be used,
and we are doing that
from dot.
So here you can see that it successfully created
koe baseimage 1.0
Based on that, we can build the second image.
So that would be
docker build -t koe/finalimage:1.0
f
dockerfile
and dot.
And there we go.
Now let's use docker image ls.
And in docker image ls,
you can see that both of the images that I just have created
have the same size,
and that's exactly what is supposed to be happening.
Now we are going to use
docker image ls
| grep koe once more
so that we are running the right images.
Now we can use docker history.
And docker history is going to be used on koe finalimage
and on koe baseimage.
And what is the thing to be observed here?
The thing to be observed is that the difference
is only in the top layer of the second image,
and for the rest, the images are the same
and the disk space is used once only.
And that is this copy-on-write thing.
Copy-on-write means that only the modifications
are going to be stored.
And as a result,
you can see that this is really all the same
and the only difference is right here in the top layer
of the second image.
And that is proof of how copy-of-write is used
to organize storage in Docker container writeable layers
in a very efficient way.
In the next video,
I will show you how to use bind mounts
in order to work with storage.