Docker's direct-lvm partition and backups

hi, 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 ?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

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.

  1. sudo systemctl stop docker
  2. rm -rf /var/lib/docker/*
  3. pvcreate /dev/sda
  4. vgcreate docker /dev/sda
  5. lvcreate --wipesignatures y -n thinpool docker -l 95%VG
  6. lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG
  7. 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:

  1. 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:

  1. systemctl daemon-reload
  2. 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 /