Docker – Storage

Storage Drivers

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.

TechnologyStorage Driver
OverlayFSoverlay or overlay2
AUFSaufs
Btrfsbrtfs
Device Managerdevicemanager
VFSvfs
ZFSzfs

Let us now discuss some of the instances in which you would use the various storage drivers −

AUFS

  • 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.

Devicemapper

  • 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.

Btrfs

  • 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.

Ovelay

  • 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.

ZFS

  • 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 issue the Docker info command use by the storage driver.

Syntax

docker info 

Options

None

Return Value

The command will provide all relative information on the Docker component installed on the Docker Host.

Example

sudo docker info 

Output

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.

aufs driver

Data Volumes

In Docker, you have a separate volume that can shared across containers. These are the data volumes. Some of the features of data volume are −

  • When the container create then they initialize.
  • They can be shared and also reused amongst many containers.
  • Any changes to the volume itself can be made directly.
  • They exist even after the container is deleted.

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 the container via the Jenkis image do by that.

data volume

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. Here is an example 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.

v option

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.

container files

Changing the Storage Driver for a Container

If you wanted to change to the storage driver used for a container, you can do so when launching the container. When using the docker run command the -volume-driver parameter can use by this. Here is an example 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.

volume driver

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 
docker inspect

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.

driver name was changed

Creating a Volume

The docker command can create by a volume using beforehand. Let’s learn more about this command.

Syntax

docker volume create –-name=volumename –-opt options

Options

  • name − This is the name of the volume create by which need.
  • opt − These are options you can provide while creating the volume.

Return Value

The command will output the name of the volume created.

Example

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.

Output

below – show by the output of the above command

creating a volume

Listing all the Volumes

You can also list all the docker volumes on a docker host. More details below- give by on this command.

Syntax

docker volume ls 

Options

None

Return Value

The command will output all the volumes on the docker host.

Example

sudo docker volume ls

Output

below – show by the output of the above command

listing all volumes

In this guide, we learned about docker storage. To know more click here.

This Post Has One Comment

Leave a Reply