How to use Docker in ThreeFold VMs

If you had trouble running Docker inside of a ThreeFold VM due to bad performance with the vfs storage driver, then this guide is for you.

In the current generation of VMs deployed from the ThreeFold Dashboard, the root filesystem is provided as a virtiofs mount inside the VM. While this has certain advantages, it’s also not very compatible with Docker. To work around that, we can provide Docker with virtual disk based storage that is compatible with Docker’s more performant storage drivers.

This method can be used with both full VMs and micro VMs, with a bit different process for each.

Full VM

In the case of a full VM, our steps are:

  1. Deploy the VM with a disk
  2. Mount the disk at /var/lib/docker permanently using fstab
  3. Install Docker

Deploy VM with disk

In the Dashboard, just click over to the disks section during the deployment flow and add a disk. The disk name doesn’t matter but you can set it if you like:

Size this disk to hold all the data you might want to use with your apps running in Docker. If the machine is only running Docker and Docker apps, you won’t need much root filesystem space. The minimum 15gb should be fine:

Mount the disk with fstab

Now deploy and connect to the VM via SSH. You can see that the disk has been mounted automatically:

df -h

image
This mount point has been set automatically during the VM’s first boot. We can change it by editing fstab using an editor like nano.

First install your editor:

apt update && apt install nano

Then edit fstab:

nano /etc/fstab

Change the mount point for vda to /var/lib/docker:


Now save the file and exit the editor. For nano, that’s: ctrl-o, enter, ctrl-x.

Next we need to refresh the fstab file and remount the disk:

systemctl daemon-reload
umount /dev/vda
mount /dev/vda

The disk should now be mounted at the new mount point:

image

Install Docker

Since the disk is now mounted at the default Docker data directory, Docker will put its data on the disk by default. So simply installing Docker in any of the usual ways is all that’s needed from here:

wget get.docker.com -O get-docker.sh
bash get-docker.sh

Micro VM

The main difference with a micro VM is that we can set the mount point directly in the deployment process:

There’s no need to edit fstab or remount the disk in this case.

Conclusion

By putting Docker’s data directory on a virtual disk, Docker will have performance comparable to other environments. While mounting the disk to /var/lib/docker is a simple way to accomplish this, it’s not the only way. It’s also possible to instruct Docker to put its data directory in another location, such as an alternative mount point.

I hope this helps, and please reply with any questions you might have :slight_smile:

1 Like

Sweet guide. I am sure it will be very useful for users exploring with Docker. Thanks.