# How to use Docker in ThreeFold VMs

**URL:** <https://staging.forum.threefold.io/t/how-to-use-docker-in-threefold-vms/4583>\
**Category:** ThreeFold Grid Utilization\
**Created:** [April 25, 2025, 6:17pm UTC](https://staging.forum.threefold.io/t/how-to-use-docker-in-threefold-vms/4583 "2025-04-25T18:17:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott](https://staging.forum.threefold.io/user_avatar/staging.forum.threefold.io/scott/32/604_2.png) [@scott](https://staging.forum.threefold.io/u/scott)\
**Post date:** [April 25, 2025, 6:17pm UTC](https://staging.forum.threefold.io/t/how-to-use-docker-in-threefold-vms/4583/1 "2025-04-25T18:17:17Z")

</div>

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:

 ![image](https://staging.forum.threefold.io/uploads/default/original/2X/c/c10772e64186d50e5343b4e4ca38ea29e2423dbf.png)

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:

 ![image](https://staging.forum.threefold.io/uploads/default/original/2X/8/8451db1a84e39b162ac69743b181b6c8746ea0e4.png)

## Mount the disk with fstab

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

```bash
df -h

```

 ![image](https://staging.forum.threefold.io/uploads/default/original/2X/6/6aa211957f4f08f27eabb519a4b7811f90711d74.png)  
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:

```bash
apt update && apt install nano

```

Then edit `fstab`:

```auto
nano /etc/fstab

```

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

 ![image](https://staging.forum.threefold.io/uploads/default/original/2X/5/5bd53f6bad800e4a5ecb48c05b516201b0ca262c.png)  
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:

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

```

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

 ![image](https://staging.forum.threefold.io/uploads/default/original/2X/8/881f663efa7ba030acf7be98f8c03c149ac9be8d.png)

## 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:

```auto
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:

 ![image](https://staging.forum.threefold.io/uploads/default/original/2X/c/c2476026a37046059a47b47438f7a2de4a321bcf.png)

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 🙂

---

<div class="post-metadata">

**Author:** ![Mik](https://staging.forum.threefold.io/user_avatar/staging.forum.threefold.io/mik/32/981_2.png) [@Mik](https://staging.forum.threefold.io/u/Mik)\
**Post date:** [April 26, 2025, 3:14pm UTC](https://staging.forum.threefold.io/t/how-to-use-docker-in-threefold-vms/4583/2 "2025-04-26T15:14:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RobertL](https://staging.forum.threefold.io/letter_avatar_proxy/v4/letter/r/a87d85/32.png) [@RobertL](https://staging.forum.threefold.io/u/RobertL)\
**Post date:** [December 30, 2025, 6:47am UTC](https://staging.forum.threefold.io/t/how-to-use-docker-in-threefold-vms/4583/3 "2025-12-30T06:47:56Z")

</div>

Can this be automated in a terraform script as well before installing apps with docker in the same script?

---

<div class="post-metadata">

**Author:** ![scott](https://staging.forum.threefold.io/user_avatar/staging.forum.threefold.io/scott/32/604_2.png) [@scott](https://staging.forum.threefold.io/u/scott)\
**Post date:** [December 30, 2025, 11:12pm UTC](https://staging.forum.threefold.io/t/how-to-use-docker-in-threefold-vms/4583/4 "2025-12-30T23:12:07Z")

</div>

Yes of course. You can set a mount point also when using Terraform to add a disk. Here’s an equivalent example snippet that does the same as I showed above:

```auto
resource "grid_deployment" "d1" {
  node = 5453
  network_name = grid_network.net.name

  disks {
    name = "data"
    size = 50
  }

  vms {
    name = "vm1"
    flist = "https://hub.grid.tf/tf-official-vms/ubuntu-24.04-latest.flist"
    cpu = 1
    memory = 2048
    rootfs_size = 15000
    entrypoint = "/sbin/zinit init"
    env_vars = {
      SSH_KEY = file("~/.ssh/id_rsa.pub")
    }
    mounts {
        disk_name = "data"
        mount_point = "/var/lib/docker"
    }
  }
}

```

This example shows a micro VM, but full VMs work in the same way.
