• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Configure Btrfs as the Storage Engine in Docker

by admin

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.

How to Disable or set SELinux to Permissive mode

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

Filed Under: DevOps, Docker

Some more articles you might also be interested in …

  1. The Ultimate Guide To Use VS Code With Windows Subsystem for Linux (WSL)
  2. How to check the status and space used by images and containers
  3. How to List / Start / Stop / Delete docker Containers
  4. How to write multiple plays and per-play privilege escalation in Ansible
  5. Understanding Variables in Bash Shell Under Linux
  6. 10 Sed (Stream Editor) Command Examples
  7. How To Change The Time Zone For A Docker Container
  8. How to install docker on CentOS / RHEL / Fedora
  9. A Beginner’s Guide To Create Files & Folders Inside Windows Subsystem For Linux
  10. Puppet Server’s Resources Cheat Sheet with Examples

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright