If you mount a host directory that already contains files to an empty volume of the container, the container can see the files stored in the host. This is an excellent way to pre-populate files for your container(s) to use. However, if the directory does not exist in the host filesystem, Docker will create the directory automatically. If the volume is non-empty and the host filesystem already contains files, Docker will obscure the mount. This means that while you won’t see the original files while the Docker volume is mounted to it, the files are not deleted, and you can recover them by unmounting the Docker volume.
We’ll look at Docker storage drivers in the next section.
Docker storage drivers
There are numerous storage driver types. Some of the most popular ones are as follows:
- overlay2: This is aproduction-ready driver and is the preferred storage choice for Docker. It works in most environments.
- devicemapper: This wasthe preferred driver for devices running RHEL and CentOS 7 and below that did not support overlay2. You can use this driver if you have write-intensive activities in your containers.
- btrfs and zfs: These drivers are write-intensive and provide many features, such as allowing snapshots, and can only be used if you are using btrfs or zfs filesystems within your host.
- vfs: Thisstorage driver should be used only if no copy-on-write filesystem is available. It is extremely slow, and you should refrain from using it in production.
Let’s concentrate on two of the most popular ones – overlay2 and devicemapper.
overlay2
overlay2 is the default and recommended storage driver in most operating systems except RHEL 7 and CentOS 7 and older. They use file-based storage and perform best when subject to more reads than writes.
devicemapper
devicemapper is block-based storage and performs the best when subject to more writes than reads. Though it is compatible and the default with CentOS 7, RHEL 7, and below, as they don’t support overlay2, it is currently not recommended in the newer versions of these operating systems that do support overlay2.
Tip
Use overlay2 where possible, but if you have a specific use case for not using it (such as too many write-intensive containers), devicemapper is a better choice.