Storage Drivers in Docker
What is Docker?
Docker is a software technology providing containers, promoted by the company Docker Inc, which provides an additional layer of abstraction and automation of operating-system-level virtualization on Windows and Linux.
Why use Docker?
- Docker takes fewer resources for containers to run applications.
- It takes 2–3 seconds to make a container and live your services.
- Containers include the minimal runtime requirements of the application, reducing their size and allowing them to be deployed quickly.
- An application and all its dependencies can be bundled into a single container that is independent of the host version of the Linux kernel, platform distribution, or deployment model. This container can be transferred to another machine that runs Docker and executed there without compatibility issues.
- Docker reduces the effort and risk of problems with application dependencies.
Storage Drivers in Docker!!!
- Storage Drivers provide a pluggable framework for managing the temporary, internal storage of a container’s writable layer.
Ideally, very little data is written to the container writable layer and we use Docker volumes to write data.
However some workloads require you to be able to write to the container’s writable layer. This is where storage drivers comes into picture.
- Docker supports a variety of storage drivers, it chooses storage drivers depending on your environment and your storage needs.
- This Storage Driver controls how images and containers are stored and managed on your Docker host.
Type of Storage Drivers: (should be used in the order)
- btrfs :
brtfs
allow for advanced options, such as creating “snapshots”, but require more maintenance and setup. Each of these relies on the backing filesystem being configured correctly. - zfs :
zfs
Allow for advanced options, such as creating “snapshots”, but require more maintenance and setup. Each of these relies on the backing filesystem being configured correctly. - overlay2 :
overlay2
is the preferred storage driver for all currently supported Linux distributions, and requires no extra configuration. - fuse-overlayfs :
fuse-overlayfs
is preferred only for running Rootless Docker on a host that does not provide support for rootlessoverlay2
. On Ubuntu and Debian 10, thefuse-overlayfs
driver does not need to be used andoverlay2
works even in rootless mode. Refer to the rootless mode documentation for details. - aufs : The
aufs
storage driver Was the preferred storage driver for Docker 18.06 and older when running on Ubuntu 14.04 on kernel 3.13 which had no support for,overlay2
. However, current versions of Ubuntu and Debian now have support foroverlay2
, which is now the recommended driver. - overlay : The legacy
overlay
driver was used for kernels that did not support the “multiple-lowerdir” feature required foroverlay2
All currently supported Linux distributions now provide support for this, and it is therefore deprecated. - devicemapper : The
devicemapper
storage driver requiresdirect-lvm
for production environments, becauseloopback-lvm
, while zero-configuration, has very poor performance.devicemapper
was the recommended storage driver for CentOS and RHEL, as their kernel version did not supportoverlay2
. However, current versions of CentOS and RHEL now have support foroverlay2
, which is now the recommended driver. - vfs : The
vfs
storage driver is intended for testing purposes, and for situations where no copy-on-write filesystem can be used. The Performance of this storage driver is poor and is not generally recommended for production use.
Docker automatically choose the storage driver that is compatible with your environment, but in some cases In order to change the storage driver, which is configured by default at the time of installation, there are 2 methods:
- Set the --storage-driver flag when starting Docker (in system unit file)
Edit the ExecStart line, adding the --storage-driver devicemapper flag:
# vi /usr/lib/system/system/docker.service
ExecStart=/usr/bin/dockerd --storage-driver <storage_driver> -H fd:// --containerd=/run/containerd/containerd.sock
Reload/restart the docker daemon
# systemctl deamon-reload
# systemctl restart docker
2. Set the storage driver using the daemon configuration file (recommended way)
# vi /etc/docker/daemon.json
{
“storage-driver” : “<storage_driver_name>”
}
Reload/restart the docker daemon
# systemctl deamon-reload
# systemctl restart docker
** Note ** we cannot use both methods on same time.
Although Docker choose the storage drivers automatically, but as per the statistic of drivers, Supported storage drivers per Linux distribution:
Storage Models:
Docker manages the persisted data using several storage methods:
FileSystem Storage:
- Used by Overlay2 & Aufs
- Data is stored in the form of a file system
- Efficiently used memory
- Inefficient with write-heavy workloads
Block Storage:
- Used by Devicemapper.
- Stores data in Block.
- Efficient with write-heavy workloads.
Object Storage:
- Stores data in external object-based storage.
- The Application must be designed to use object-based storage.
- Flexible and Scalable.
How to Check your current storage driver?
$ docker info
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Storage Driver: overlay2
Thanks for reading!!!