Proxmox is one of the best Linux distro available to run your home-lab on, relying primarily on KVM and LXC for it’s virtualisation and containerization features, however the one place i feel it falls short is in Docker support, Many apps today like nextcloud provide official Docker images for ease of deployment however very few exist for LXC.
We can easily rectify this using already inbuilt features of Proxmox to run Docker inside an LXC conatiner with virtually no overhead.
Since Installing Docker on Proxmox bare-metal is strongly discouraged we can use a unprivileged LXC conatiner as our Docker host.
We just need to create a conatiner with the nesting
,keyctl
and the fuse
feature enabled for Docker to work.
Install using SSH/CLI
Login the server using your preffered method like SSH
Before we create our host LXC container we will need a base OS image for it.
Download a LXC base system Image
- Update the repo
Update the Container image repository for LXC using
pveam update
- Choose a system Image
List available system images for download using
pveam available --section system
- Download the base system Image
Download your choice of one of the base system images using
pveam download <Storage Pool> <Image Name>
We will be using Ubuntu 21.04 for this tutorial, and we will download that image to “Virt-dir” Pool.
So we can run
pveam download Virt-dir ubuntu-21.04-standard_21.04-1_amd64.tar.gz
You can view the status of all your Storage Pools with pvesm status
Create the host conatiner
Create root storage for our host container
Create the root filesystem for our host container in any of your available storage pools
We will use “local-zfs” as our storage pool for this tutorial
- Allocate a new device to your future container using
pvesm alloc --format subvol <Target Storage Pool> <VMID> vm-<Diskname> <Desired Storage>
So we will use something like this to allocate a 8GB disk to our vm 111
pvesm alloc --format subvol local-zfs 111 subvol-111-disk-1 8G
- Fix Permissions
Now we need to Change the permissions on that device for our OS to be able to use it, We will change the owner to 100000
(LXC Root User) with
chown -R 100000:100000 $(pvesm path <Storage Pool>:<Disk id>)
So we will use
chown -R 100000:100000 $(pvesm path local-zfs:subvol-111-disk-1)
Create the host LXC container on which our Docker will run
Now we will create the host conatiner to install Docker using
pct create <VMID> \
<Storage Pool>:<Base image> \
--unprivileged <Conatiner Privilege> \
--onboot <Start on Boot> \
--hostname <CT Hostname> \
--cores <CPU Cores Alloted> \
--memory <RAM alloted in MB> \
--features <Set conatiner featured> \
--password <CT Root Password> \
--swap <Disable Swap> \
--rootfs <CT Root disk> \
--net0 <Define CT network> \
In our case the base image is downloaded in the “Virt-dir” Directory and “local-zfs” as our desired target storage for our host container so our command would look something like this
pct create 111 \
Virt-dir:vztmpl/ubuntu-21.04-standard_21.04-1_amd64.tar.gz \
--unprivileged 1 \
--onboot 0 \
--hostname "Docker-host" \
--cores 4 \
--memory 4096 \
--features keyctl=1,fuse=1,nesting=1 \
--password "hunter2" \
--swap 0 \
--rootfs local-zfs:subvol-111-disk-1 \
--net0 name=eth0,bridge=vmbr0,ip=dhcp
Start the container with pct start <VMID>
Install Docker
Get into your newly created conatiner’s root shell with pct exec <VMID> bash
and update the system.
For us that’ll be
apt update && apt dist-upgrade
-
Now we can simply follow the Official Docker Documentaion and install Docker as usual.
-
Alternatively you can install the
docker
ordocker.io
package from your distro’s repos
For us on Ubuntu 21.04 that’ll be
apt update && apt install docker.io
Enable Docker using
systemctl enable --now docker
Let me know if i missed anything.