- In this video, we are going to explore storage drivers.
So, storage drivers allow for writing data
in the writable layer of the container.
And data written to this way is not persistent
and performance is not good.
The writable layer is created when learning any container.
And storage drivers handle how delays interact
with one another.
For local use, the local driver and the sshfs drive
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 device mapper.
And every container stack
on the different distributions commenter 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.
We're working with storage
in Docker containers a CoW strategy is used.
Let'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.
Using CoW strategy guarantees that only modifications
are in the writable 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 writable layers is stored.
And for write-intense applications the 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 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 directly CoW test
as you through that directory as well.
And from there I'm creating a simple file,
simple shell script, hello.sh.
This is the best 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 of requirement for any a file
you want to run as an executable on Linux
and then we can create Dockerfile.base
I'm using vim on Dockerfile.base
and in there from ubuntu 2004, copy. /app.
Then I'm going to create Dockerfile,
and in Docker file, we are using, from koe
which happens to be ducks for CoW,
Koe is not COW by the way with the animal,
base image 1.0 that's a base image that they still have
to create and CMD/app/hello.sh
Now we can build the base image.
So Docker builds -t koe/base-image:1.0
and we force the Docker file base to be used
and we are doing that from dot.
So here you can see that it's successfully
created koe base image 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 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 LS,
Docker image LS by 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 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 writable 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.