- 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 to 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
and the sshfs driver 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,
the zfs, or devicemapper.
And every container stack
on the different distributions come with their own 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 column
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 are started based on one image,
only the difference between the container
writeable layers is stored.
And for write intense applications,
this strategy however is not so efficient
and it's 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 Docker files.
And here is part two,
in which we are going to use these Docker files.
Let me run this demo for you.
So I will create a directory CRW test
and go to that directory as well.
And from there I'm creating a simple file,
simple scale script, hello.sh.
This is a bash scale 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 dot to /app.
Then I'm going to create Docker file.
And in Docker file, we are using from koe,
which happens to be Dutch for cow.
Koe is not CoW by the way, but the animal.
Base image 1.0, that's the base image
that they still have to create.
And CMD /app/hello.sh.
Now we can build the base image.
So Docker build minus T koe/base-image 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 base image 1.0.
Based on that we can build the second image.
So that would be Docker build
minus T koe/final-image:1.0 minus F Docker file 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, oh, I mean Docker ls
Docker image ls pipe and 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 final image and on koe base image.
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 of 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 on 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.