Docker - zbrewer/homelab GitHub Wiki

Installation

Docker should be installed on either Ubuntu Server or Debian, running natively or as a VM. A container might work but nested containerization may be less stable. The instructions on the Docker website can be followed for installing from a repository on Debian or Ubuntu. It can then be updated using normal package update methods (apt).

Host Filesystem Resizing

If you're like me and running Docker in a VM, you might need to occasionally expand the VM's storage as you install more containers and store more data. This can be done by increasing the size of the virtual disk and then editing the partition table. Note that this is a potentially dangerous operation with the potential for data loss. Backups are advised before proceeding.

To start, you first need to expand the virtual disk in Proxmox (or your hypervisor of choice). It's easiest if you go ahead and shutdown the VM. Then, on the Hardware tab of the VM's settings page in the Proxmox UI, click on the virtual disk you want to resize and then click on Disk Action at the top. Select Resize and then enter the amount to grow the disk.

After that is done, we need to resize the partition on the disk. If this is not also your root filesystem, you might be able to unmount it and do do the resize from the guest VM using something like cfdisk (interactive terminal tool), fdisk, parted, or growpart (from the cloud-utils package). For me, since it's also my root filesystem, I need to do the resize from a live CD. I found that the easiest way to do that was to use GParted. Download the ISO in Proxmox and attach it to the VM's CD/DVD drive on the Hardware page. Then, boot the VM and press ESC during boot to enter the boot menu. Select the GParted DVD and wait for it to boot. Once it does, resize your partitions and apply the changes. Then power off and "remove" the GParted disk.

At this point, you should be able to reboot the guest VM and run lsblk to see the new partition sizes. If you also have logical volumes (LVMs) you may need to expand those as well. You can use the pvs command to display the volume group(s) and ensure that the free space is now what you expect (what you just added). Then you can use the command lvresize -l +100%FREE /dev/mapper/<vg>-<lv> to resize the logical volume (represented by the <lv> placeholder) to 100% of the free space in its volume group (the <vg> placeholder). Then run resize2fs /dev/mapper/<vg>-<lv> to resize the file system. At this point, you can reboot to make sure everything worked.

Example

Here is the output of lsblk on my Docker host. Note that, knowing what I know now, this is not a setup I would recommend.

NAME                     MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda                        8:0    0   256G  0 disk 
├─sda1                     8:1    0   487M  0 part /boot
├─sda2                     8:2    0     1K  0 part 
└─sda5                     8:5    0 255.5G  0 part 
  ├─docker--1--vg-root   254:0    0 144.6G  0 lvm  /
  └─docker--1--vg-swap_1 254:1    0   980M  0 lvm  [SWAP]

In this case, /dev/sda1 is my boot partition, /dev/sda2 is an extended partition that contains /dev/sda5, the physical volume LVM is using. You can also see two items of type lvm within /dev/sda5: docker--1--vg-root and docker--1--vg-swap_1. These are two logical volumes inside of a single volume group. The single dash (-) is the separator between the volume group and the logical volume. The double dash (--) is effectively an escaped dash that is part of the volume group name or the logical volume name. In this case, the volume group is called docker-1-vg and the logical volumes are root and swap_1, respectively. This can all be seen more easily in the output of pvs before I did a resize:

PV         VG          Fmt  Attr PSize    PFree  
/dev/sda5  docker-1-vg lvm2 a--  <255.52g 110.00g

Here we can see that the physical volume is /dev/sda5, the volume group is docker-1-vg, and the free space is 110G. Armed with this information, we can grow the logical volume. To grow my / volume, this would look like lvresize -l +100%FREE /dev/mapper/docker--1--vg-root. You can see that part after /dev/mapper/ is the volume group and logical volume separated by a - in the same format that was printed by lsblk. You can also use /dev/<vg>/<lv>, if you wish (i.e. /dev/docker-1-vg/root). Finally, use resize2fs with the same device as in the lvresize command to resize the filesystem and finish the resize operation. This would look like resize2fs /dev/mapper/docker--1--vg-root for me.

At this point, reboot and run pvs and df -h to make sure the space is reported as expected.

⚠️ **GitHub.com Fallback** ⚠️