Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

Container or Virtual Machine?

In Proxmox VE, a container runs a Linux distribution on the host's kernel; a virtual machine has its own kernel and can run any operating system. Choose a container for Linux services that need no kernel modules of their own, and a virtual machine for other operating systems, custom kernels, or strong isolation. The wider comparison is in LXC vs Docker.

Step 1: Get a Template

Containers are created from templates: compressed root file systems of a distribution. Refresh the list, look at it, and download one:

pveam update
pveam available --section system
pveam download local TEMPLATE_NAME
pveam list local

Replace TEMPLATE_NAME with a name from the list, for example the current Debian or Ubuntu standard template. In the web interface the same is under the local storage, CT Templates, Templates.

Step 2: Create the Container

The Create CT button walks through the settings. From the shell:

pct create 200 local:vztmpl/TEMPLATE_FILE \
  --hostname web1 --unprivileged 1 \
  --cores 2 --memory 2048 --swap 512 \
  --rootfs local-lvm:8 \
  --net0 name=eth0,bridge=vmbr0,ip=dhcp \
  --ssh-public-keys /root/.ssh/id_ed25519.pub \
  --onboot 1
pct start 200

Memory is in megabytes and local-lvm:8 creates an 8 GB root disk on that storage. Set the root password afterward with pct enter 200 and passwd, rather than passing it as an option. For a static address, write ip=203.0.113.20/24,gw=203.0.113.1 instead of dhcp.

Unprivileged by Default, and Why

In an unprivileged container, root inside the container is mapped to an unprivileged user ID on the host. If a process breaks out of the container, it has no special rights on the host. The web interface ticks Unprivileged container by default; keep it that way unless a specific need, such as certain mounts, forces a privileged one.

The cost: files from bind mounts appear owned by high user IDs on the host, so permissions need planning.

Everyday Commands

CommandWhat it does
pct listLists containers
pct enter 200Opens a root shell inside
pct shutdown 200Clean shutdown
pct stop 200Hard stop
pct config 200Shows the settings
pct set 200 --memory 4096Changes memory

Bind Mounts

A bind mount makes a host directory visible inside the container, for example for shared data:

pct set 200 --mp0 /srv/data,mp=/data

In an unprivileged container, give the host directory to the mapped user ID (by default the user ID inside the container plus 100000, so root becomes 100000) or set up an ID mapping. Never solve it with world-writable permissions.

Nesting for Docker Inside

pct set 200 --features nesting=1,keyctl=1

Nesting allows containers inside the container. Docker can then run, but storage drivers and security profiles cause trouble on some setups. keyctl is needed for Docker in an unprivileged container, and nesting exposes some of the host's procfs and sysfs contents to the container. For maximum isolation and live migration, the Proxmox VE documentation recommends nesting containers inside a virtual machine instead. See what Docker is.

Backups and Snapshots

pct snapshot 200 before-upgrade
pct rollback 200 before-upgrade
vzdump 200 --storage backup-store --mode snapshot

A rollback discards every change made since the snapshot, so copy out any newer data you need first. Snapshots need storage that supports them, such as LVM-thin or ZFS, and live on the same storage as the container. Real backups go elsewhere, best to a Proxmox Backup Server.

Limits of Containers

  • No kernel of their own: kernel updates and modules are the host's business.
  • Migration: a running container cannot be live-migrated; a restart migration shuts it down, moves it, and starts it on the other node.
  • Some software refuses to run: programs that load kernel modules or need raw devices belong in a virtual machine.
Was this answer helpful?
Loading...