Docker is an open platform management tool for Linux Containers. It provides a means for developers and system administrators to build and package applications into lightweight containers.
Docker uses devicemapper devices as the default storage engine. To use Btrfs as the storage engine, perform the following steps. Note that Red Hat Enterprise Linux (RHEL) removes the Btrfs storage driver from their build of Docker, both on the Extra Packages for Enterprise Linux (EPEL) repository and the version released for RHEL7.
Use the systemctl command to stop the docker service. Use the mkfs.btrfs command to create a Btrfs file system on a block device. Use the blkid command to determine the UUID of the Btrfs file system. For the example used in this post, I am assuming you have already configured the btrfs filesystem and will focus only on docker configuration to use the btrfs filesystem as storage engine.
1. Create the /etc/systemd/system/var-lib-docker.mount file as follows:
[Unit] Description = Docker Image Store [Mount] What = UUID=[UUID for the Btrfs file system] Where = /var/lib/docker Type = btrfs [Install] WantedBy = multi-user.target
2. Use the systemctl command to enable and start the var-lib-docker.mount target.
# systemctl enable var-lib-docker.mount # systemctl start var-lib-docker.mount
3. Set the SELinux mode to “Permissive“. SELinux does not currently support the Btrfs storage driver.
4. Edit the /etc/sysconfig/docker file and set the OPTIONS variable as follows:
# vi /etc/sysconfig/docker OPTIONS=-s btrfs
5. Copy the /usr/lib/systemd/system/docker.service file to /etc/systemd/system/docker.service.
# cp -p /usr/lib/systemd/system/docker.service /etc/systemd/system/docker.service
6. Edit /etc/systemd/system/docker.service and add Requires and After entries for the var-lib-docker.mount target as follows:
# vi /etc/systemd/system/docker.service [Unit] Description=Docker Application Container Engine Documentation=http://docs.docker.com Requires=var-lib-docker.mount After=network.target docker.socket Requires=docker.socket After=var-lib-docker.mount [Service] Type=notify EnvironmentFile=-/etc/sysconfig/docker EnvironmentFile=-/etc/sysconfig/docker-storage ExecStart=/usr/bin/docker -d -H fd:// $OPTIONS $DOCKER_STORAGE_OPTIONS LimitNOFILE=1048576 LimitNPROC=1048576 [Install] WantedBy=multi-user.target
7. If your system needs to use a web proxy to access the Docker Hub Registry, edit the /etc/sysconfig/docker file and add the following lines. Replace [proxy_URL:port] with the appropriate URL and port number for your web proxy.
# vi /etc/sysconfig/docker HTTP_PROXY="[proxy_URL:port]" HTTPS_PROXY="[proxy_URL:port]"
8. Use the systemctl command to enable and start the docker service.
# systemctl enable docker # systemctl start docker
9. The docker info command now shows Btrfs as the storage driver:
# docker info Storage Driver: btrfs