Docker has multiple storage drivers that allow one to work with the underlying storage devices. The following table shows the different storage drivers along with the technology used for the storage drivers.
Technology | Storage Driver |
---|---|
OverlayFS | overlay or overlay2 |
AUFS | aufs |
Btrfs | brtfs |
Device Manager | devicemanager |
VFS | vfs |
ZFS | zfs |
Let us now discuss some of the instances in which you would use the various storage drivers −
This is a stable driver; can be used for production-ready applications.
It has good memory usage and is good for ensuring a smooth Docker experience for containers.
There is a high-write activity associated with this driver which should be considered.
It’s good for systems which are of Platform as a service type work.
This is a stable driver; ensures a smooth Docker experience.
This driver is good for testing applications in the lab.
This driver is in line with the main Linux kernel functionality.
This driver is in line with the main Linux kernel functionality.
There is a high-write activity associated with this driver which should be considered.
This driver is good for instances where you maintain multiple build pools.
This is a stable driver and it is in line with the main Linux kernel functionality.
It has a good memory usage.
This driver is good for testing applications in the lab.
This is a stable driver and it is good for testing applications in the lab.
It’s good for systems which are of Platform-as-a-Service type work.
To see the storage driver being used, issue the docker info command.
docker info
None
The command will provide all relative information on the Docker component installed on the Docker Host.
sudo docker info
The following output shows that the main driver used is the aufs driver and that the root directory is stored in /var/lib/docker/aufs.
In Docker, you have a separate volume that can shared across containers. These are known as data volumes. Some of the features of data volume are −
Let’s look at our Jenkins container. Let’s do a docker inspect to see the details of this image. We can issue the following command to write the output of the docker inspect command to a text file and then view the file accordingly.
sudo docker inspect Jenkins > tmp.txt
When you view the text file using the more command, you will see an entry as JENKINS_HOME=/var/Jenkins_home.
This is the mapping that is done within the container via the Jenkins image.
Now suppose you wanted to map the volume in the container to a local volume, then you need to specify the –v option when launching the container. An example is shown below −
sudo docker run –d –v /home/demo:/var/jenkins_home –p 8080:8080 –p 50000:50000 jenkins
The –v option is used to map the volume in the container which is /var/jenkins_home to a location on our Docker Host which is /home/demo.
Now if you go to the /home/demo location on your Docker Host after launching your container, you will see all the container files present there.
If you wanted to change to the storage driver used for a container, you can do so when launching the container. This can be done by using the –volume-driver parameter when using the docker run command. An example is given below −
sudo docker run –d --volume-driver=flocker –v /home/demo:/var/jenkins_home –p 8080:8080 –p 50000:50000 jenkins
The –volume-driver option is used to specify another storage driver for the container.
To confirm that the driver has been changed, first let’s use the docker ps command to see the running containers and get the container ID. So, issue the following command first −
sudo docker ps
Then issue a docker inspect against the container and put the output in a text file using the command.
sudo docker inspect 9bffb1bfebee > temp.txt
If you browse through the text file and go to the line which says VolumeDriver, you will see that the driver name has been changed.
A volume can be created beforehand using the docker command. Let’s learn more about this command.
docker volume create –-name=volumename –-opt options
name − This is the name of the volume which needs to be created.
opt − These are options you can provide while creating the volume.
The command will output the name of the volume created.
sudo docker volume create –-name = demo –opt o = size = 100m
In the above command, we are creating a volume of size 100MB and with a name of demo.
The output of the above command is shown below −
You can also list all the docker volumes on a docker host. More details on this command is given below −
docker volume ls
None
The command will output all the volumes on the docker host.
sudo docker volume ls
The output of the above command is shown below −