Docker's direct-lvm partition and backups

Posted February 6, 2016 10.1k views

I’m looking to get started on Digitalocean with a docker vm. Now, the currently recommended way to run Docker is through direct-lvm.
This pretty much means creating a volume and doing

lvcreate --wipesignatures y -n data direct-lvm -l 95%VG
lvcreate --wipesignatures y -n metadata direct-lvm -l 5%VG

is this viable on Digitalocean ?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Using direct-lvm requires a free block device. DigitalOcean Droplets are setup with a single partition by default which makes this slightly difficult. Though with the addition of block storage (currently in beta), it becomes much easier.

For example, booting up a new 16.04 Droplet with Docker installed and a block storage volume attached, we can see the free device at sda as well as the loopback device created by Docker’s defaults:

$ lsblk 
sda                          8:0    0  100G  0 disk 
vda                        253:0    0   30G  0 disk 
└─vda1                     253:1    0   30G  0 part /
loop0                        7:0    0  100G  0 loop 
└─docker-253:1-784525-pool 252:0    0  100G  0 dm   
loop1                        7:1    0    2G  0 loop 
└─docker-253:1-784525-pool 252:0    0  100G  0 dm 

For all the information setting up direct-lvm mode for production see the Docker documentation. Though, here’s a quick run through. First we will stop Docker and then create a new volume and thin pool.

  • sudo systemctl stop docker
  • rm -rf /var/lib/docker/*
  • pvcreate /dev/sda
  • vgcreate docker /dev/sda
  • lvcreate --wipesignatures y -n thinpool docker -l 95%VG
  • lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG
  • lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta

Now edit the file /etc/lvm/profile/docker-thinpool.profile to configure auto-extending of the thin pool:

activation {

Next, apply the change:

  • lvchange --metadataprofile docker-thinpool docker/thinpool

Then, we will configure Docker itself to use the new device. This can be done with command line arguments when starting Docker, but with systemd it is simpler to edit /etc/docker/daemon.json to include:

     "storage-driver": "devicemapper",
     "storage-opts": [

Finally, let’s restart Docker:

  • systemctl daemon-reload
  • systemctl start docker

Now that we’re done, you can see that the loopback device is gone and sda has been configured for LVM:

# lsblk
sda                       8:0    0  100G  0 disk 
├─docker-thinpool_tmeta 252:0    0 1020M  0 lvm  
│ └─docker-thinpool     252:2    0   95G  0 lvm  
└─docker-thinpool_tdata 252:1    0   95G  0 lvm  
  └─docker-thinpool     252:2    0   95G  0 lvm  
vda                     253:0    0   30G  0 disk 
└─vda1                  253:1    0   30G  0 part /
by finid
There are two methods for installing Docker on Ubuntu 16.04. One method involves installing it on an existing installation of the operating system. The other involves spinning up a server with a tool called Docker Machine that auto-installs Docker on it. In this tutorial, you'll learn how to install and use it on an existing installation of Ubuntu 16.04.