Skip to content
May 11, 2015 / windperson

Run Docker on CentOS 6.5 using Btrfs as storage driver

Enable btrfs support

Install btrfs then add to kernel module:

sudo yum install -y btrfs-progs
sudo mprobe btrfs

To add permanently for next boot:

sudo bash -c "echo modprobe btrfs >> /etc/rc.modules"
sudo chmod +x /etc/rc.modules

Create btrfs partition

Note: the following assume a new empty disk attached on /dev/sdb:

  1. Create a new LVM partition using fdisk:
    sudo fdisk -c /dev/sdb
    

    Or more automatically:

    echo -e "o\nn\np\n1\n\n\nw" | sudo fdisk -c /dev/sdb
    
  2. Create “Physical Volume” using pvcreate:
    sudo pvcreate /dev/sdb1
    
  3. Create “Logic Volume Group” docker_btrfs using vgcreate:
    sudo vgcreate docker_btrfs /dev/sdb1
    
  4. Create “Logic Volume” docker_btrfs01 using 100% remaining disk free space and belonging to docker_btrfs logic volume group using lvcreate:
    sudo lvcreate -l 100%FREE -n docker_btrfs01 docker_btrfs
    
  5. Format to Btrfs file system using mkfs.btrfs:
    sudo mkfs.btrfs /dev/docker_btrfs/docker_btrfs01
    
  6. Mount created partition to /var/lib/docker:
    sudo bash -c "echo \"/dev/docker_btrfs/docker_btrfs01 /var/lib/docker btrfs defaults 0 0\" >> /etc/fstab"
    sudo mount -a
    

Then we can use df or mount to verify configuration is correct:

sudo df -T
sudo mount

Install docker in CentOS 6.5

Note: to run Docker you will need kernel version 2.6.32-431 or higher.

  1. Install docker v1.6 from epel-testing repository:
    sudo yum install -y epel-release
    sudo yum install -y docker-io --enablerepo=epel-testing
    
  2. Since the binary distribution packaged by EPEL can not use btrfs as underlying storage driver, we need to replace it with official build from Docker web site:
    wget https://get.docker.com/builds/Linux/x86_64/docker-latest -O docker
    chmod +x docker
    sudo mv docker /usr/bin
    
  3. Add “-s btrfs” in other_args environment variable in docker config file: /etc/sysconfig/docker.

    Docker config file

    /etc/sysconfig/docker

  4. And everything is ready to go, start docker service 🙂
    sudo service docker start
    

    Start docker service

We can use “sudo docker info” command to verify it surely using btrfs:

Verify using btrfs storage driver using docker info

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: