Understanding Docker Storage Drivers: Choosing the Right Option for Your Needs

Ashish Dwivedi
4 min readJul 6, 2023

--

In the world of containerization, Docker has emerged as the go-to solution for efficient software deployment. A key factor that contributes to Docker's success is its storage drivers, which dictate how containers and their data are stored and accessed. Today, we embark on a journey to unravel the mysteries of Docker storage drivers, focusing on two popular options: overlay2 and devicemapper.

The Drivers Behind Docker Storage: Docker offers a variety of storage driver types, each with its own unique set of features and compatibility. Let's dive into the most popular ones and discover what makes them special:

  1. Overlay2: The Eager Performer Overlay2 takes center stage as the default and recommended storage driver for most operating systems. With its file-based storage approach, overlay2 shines when it comes to handling more reads than writes. If you're running Ubuntu or a Debian-based system, this driver is your perfect companion, ensuring smooth sailing for your containers.
  2. Aufs: The Former Champion Once the preferred storage driver for Docker, aufs was reliable and production-ready. However, the rise of overlay2, with its superior performance and broader adoption, has overshadowed aufs in recent times. It's time for aufs to gracefully step aside and make room for the new favorite.
  3. Devicemapper: The Power Player For devices running RHEL and CentOS 7 and older versions, devicemapper takes the spotlight. As a block-based storage driver, it thrives in environments where write-intensive activities are the norm. If your containers demand a robust solution for handling frequent writes, devicemapper is your ally.
  4. Btrfs and ZFS: Features Galore If you're a fan of advanced features like snapshots, btrfs and zfs storage drivers have got you covered. Designed for write-intensive workloads, these drivers can work wonders when paired with btrfs or zfs filesystems. However, make sure your host environment supports these filesystems before diving into their feature-rich world.
  5. VFS: The Last Resort When all else fails, the Virtual File System (VFS) comes to the rescue. VFS is the storage driver of choice only when no other copy-on-write filesystem options are available. However, be warned: VFS is sluggish and definitely not suited for production environments. Use it sparingly and as a temporary solution if absolutely necessary.

Unveiling Overlay2 and Devicemapper: Now that we've explored the vast landscape of Docker storage drivers, let's zoom in on the stars of our show: overlay2 and devicemapper.

  1. Overlay2: Where Efficiency Meets Simplicity Overlay2 steals the limelight as the default and recommended storage driver for most operating systems. With its file-based storage approach, it thrives when the number of read operations outshines write activities. If you're running Ubuntu or a Debian-based system, overlay2 holds the key to seamless container management and optimized performance.
  2. Devicemapper: Unleashing the Power of Writes Devicemapper steps up as a block-based storage driver, catering to environments with a heavy focus on write-intensive operations. While it serves as the default option for older versions of CentOS and RHEL that lack overlay2 support, it's not the recommended choice for the latest iterations of these operating systems. However, if your containers demand intense write capabilities, devicemapper is the knight in shining armor you need.

Configuring the Storage Driver: Now that we have a deeper understanding of overlay2 and devicemapper, let's seeprocess of configuring the storage driver to suit your needs:

  1. Check the Current Storage Driver: To begin, let's check which storage driver is currently in use. Open a terminal and run the command "docker info | grep 'Storage Driver'". The output will display the active storage driver, which, in our case, is overlay2.
  2. Changing to Devicemapper (Example): If you find yourself in a scenario where devicemapper is the preferred choice, here's how you can configure it:
  • Open the "/etc/docker/daemon.json" file using your favorite text editor. If you're comfortable with Vim, run the command "vim /etc/docker/daemon.json".
  • Add the following entry to the daemon.json configuration file:

{

"storage-driver": "devicemapper"

}

  • Save the changes and exit the editor.

3. Restarting the Docker Service: Once you've modified the daemon.json file, it's time to restart the Docker service to apply the changes. Execute the command "sudo systemctl restart docker" in your terminal.

4. Verifying the Storage Driver: To confirm that the storage driver has been successfully changed, run the command "docker info | grep 'Storage Driver'". The output should now reflect the updated storage driver, which, in our case, is devicemapper.

A Word of Caution: Changing the storage driver will result in the removal of existing containers from the disk. Therefore, exercise caution when making such modifications, especially in production environments. Additionally, be aware that pulling images again will be necessary as local images will no longer exist.

Overlay2 and devicemapper have showcased their prowess as versatile options for optimizing container storage and performance. Remember to choose the storage driver that aligns with your specific requirements, and always exercise caution when modifying the configuration. With the right storage driver at your disposal, your Docker containers are poised to embark on a seamless voyage of efficiency and scalability.

Keep Exploring>>>

--

--

No responses yet