Installing Docker server in the Homelab

The first VM that will be created is for a server to run docker and manage applications using containers. The template that we created earlier will be used to deploy the VM.

Step 1 Create Virtual Machine

SSH into the proxmox machine and execute the below commands to create a virtual machine with the below details

ConfigValue
Machine ID501
Machine Namedocker
RAM16GB
Boot1true
Order21
Time330
MAC AddressBC:24:11:2E:C1:93
vmid=501
onboot=1 #to start on boot
name=docker
ram=16384

sudo qm stop $vmid
sudo qm destroy $vmid
sudo qm clone 9001 $vmid --name $name --full
sudo qm set $vmid --onboot $onboot
sudo qm resize $vmid scsi0 +50G 
sudo qm set $vmid --memory $ram
sudo qm set $vmid -net0 virtio=BC:24:11:2E:C1:93,bridge=vmbr0
sudo qm set $vmid --startup order=1,up=30
sudo qm start $vmid

Verify that the VM is up & running using the proxmox webUI and login into the machine. For easy access create a ~/.ssh/config file with the below information.

Host docker.home.lab
  Hostname 10.10.10.5
  User ubuntu

Step2: System Tweaks

Make some system level changes for better performance.

sudo nano /etc/sysctl.conf
# Add the following lines
vm.swappiness=10
vm.vfs_cache_pressure = 50
fs.inotify.max_user_watches=1048576

Apply the changes using the below command

sudo sysctl -p

Summary of Each Setting

  • vm.swappiness = 10 Reduces the tendency for the system to swap to disk and keeps more data in RAM for better performance.
  • vm.vfs_cache_pressure = 50 Adjusts how aggressively the kernel reclaims memory used by the file system cache. A value of 50 is a balanced choice.
  • fs.inotify.max_user_watches = 262144 Increases the number of files a user can monitor simultaneously via inotify, useful for applications that require file watching on large numbers of files.

Step 3: Install Docker Dependencies

It’s always a good idea to update your package index before installing anything and ensure that your system has the necessary dependencies and other important stuff that we use later on this machine. Refer Docker official site for more information

sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release ntp htop zip unzip gnupg apt-transport-https ca-certificates net-tools ncdu apache2-utils acl

Set up Docker’s apt repository.

Download and add Docker’s official GPG key to verify the packages:

sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Install the latest Docker packages

Install Docker CE (Community Edition) and other required docker packages. Add the current user to the docker group. So that docker commands can be executed without sudo.

sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER
# Logout and login to run docker commands without sudo
exit

Version Check

Let us check whether we are able to access docker commands without sudo

docker --version #should show the version you are running.

Folder structuer to organise

As the homelab grows, so does the complexity of managing Dockerfiles, docker-compose files, and environment configurations. A clear and well-structured folder layout helps keep your project maintainable, scalable, and collaborative.

Create the below structure and files to organise the content

mkdir -p ~/docker/data # To store all the important data
mkdir -p ~/docker/logs # To have all the logs at one place
mkdir -p ~/docker/scripts # Store the docker scripts to execute
mkdir -p ~/docker/secrets # To save the passwds and other important stuff.  
touch ~/docker/.env # Environment file 
touch ~/docker/docker-compose.yml # Master docker compose file.

Why a Master Docker Compose?

When managing multiple services (traefik, nginx, sonarr… etcetra) or multiple environments (like dev, prod, test), it’s helpful to break down Docker Compose configuration into smaller, purpose-specific files and combine them with a master compose file.

Before we move on installing traefik container lets update the environment file (.env) with just two lines.

nano ~/docker/.env

TZ="America/New_york" # Your timezone
DOCKERHOME=/home/ubuntu/docker


  1. Enable auto-start of this VM when host reboots. ↩︎

  2. VM will start first in the boot sequence after a reboot of proxmox ↩︎

  3. The VM will wait 30 seconds after the host boots before starting. ↩︎