← Zurück zum Blog

Incus-CLI-Spickzettel – die wichtigsten Befehle für den Alltag

Incus-CLI-Spickzettel – die wichtigsten Befehle für den Alltag

Manche Incus-Befehle vergesse ich ständig. Vor allem die, die ich nicht jeden Tag brauche. Deshalb dieser Leitfaden – für mich und alle, die nicht jede Woche ein neues Device-Profil anlegen.

Instanzen verwalten

# Container starten
incus launch images:debian/12 mein-container

# VM starten
incus launch images:debian/12 mein-vm --vm

# Container mit Limit starten
incus launch images:debian/12 mein-container \
  --config limits.memory=1GiB \
  --config limits.cpu=2

# Container mit fester IP
incus launch images:debian/12 mein-container
incus config device override mein-container eth0 ipv4.address=10.68.100.50
incus restart mein-container

# Alle Instanzen anzeigen
incus list
incus list -c n,s,4,P

# Detaillierte Informationen
incus info mein-container
incus info mein-container --resources
incus info mein-container --show-log

# Instanz starten / stoppen / neustarten
incus start mein-container
incus stop mein-container
incus restart mein-container

# Shell im Container
incus exec mein-container -- bash
incus exec mein-container -- sh -c "apt update && apt upgrade -y"

# Befehl als bestimmter Benutzer
incus exec mein-container -- su -l benutzer -c "whoami"

# Container löschen
incus delete mein-container
incus delete mein-container --force             # läuft noch
incus delete mein-container --force --project mein-projekt

Images

# Verfügbare Images durchsuchen
incus image list images:                       # alle Images
incus image list images:debian                 # Debian-Images
incus image list images:ubuntu/24.04           # spezifische Version
incus image list images:alpine                 # Alpine-Linux

# Image lokal kopieren (für Offline-Betrieb)
incus image copy images:debian/12 local: --alias debian12

# Lokale Images anzeigen
incus image list
incus image list --format json                 # für Scripting

# Image löschen
incus image delete <fingerprint>

# Image-Informationen
incus image info <alias>

Devices (NIC, Disk, Proxy)

Alle Devices werden pro Instanz hinzugefügt oder entfernt.

# Netzwerk-Device (NIC) hinzufügen
incus config device add mein-container eth0 nic \
  name=eth0 \
  network=incusbr0

# NIC auf managed Bridge mit fester IP
incus config device add mein-container eth0 nic \
  name=eth0 \
  network=incusbr0 \
  ipv4.address=10.68.100.100

# NIC im macvlan-Mode (eigene IP im LAN)
incus config device add mein-container eth0 nic \
  nictype=macvlan \
  parent=enp0s3

# NIC überschreiben (z. B. IP ändern)
incus config device override mein-container eth0 ipv4.address=10.68.100.50

# Disk einbinden (vom Host in den Container)
incus config device add mein-container daten disk \
  source=/pfad/auf/host \
  path=/pfad/im/container

# Disk mit Beschränkung (Read-Only)
incus config device add mein-container daten disk \
  source=/pfad/auf/host \
  path=/pfad/im/container \
  readonly=true

# Proxy-Device (einfach – ohne NAT)
incus config device add mein-container webproxy proxy \
  listen=tcp:0.0.0.0:8080 \
  connect=tcp:127.0.0.1:80

# Proxy-Device mit NAT (Client-IP bleibt erhalten)
incus config device add mein-container webproxy proxy \
  listen=tcp:192.168.1.100:8080 \
  connect=tcp:10.68.100.100:80 \
  nat=true

# Proxy mit Proxy Protocol
incus config device add mein-container webproxy proxy \
  listen=tcp:0.0.0.0:8080 \
  connect=tcp:127.0.0.1:80 \
  proxy_protocol=true

# Unix-Socket weiterleiten
incus config device add mein-container dockerproxy proxy \
  listen=unix:/var/run/docker-proxy.sock \
  connect=unix:/var/run/docker.sock

# Alle Devices einer Instanz anzeigen
incus config device list mein-container

# Device entfernen
incus config device remove mein-container webproxy

Profile

Profile sind Vorlagen, die auf eine oder mehrere Instanzen angewendet werden. Das Default-Profil wird automatisch auf jede neue Instanz angewendet.

# Profile anzeigen
incus profile list
incus profile show default

# Neues Profil erstellen
incus profile create mein-webserver-profil

# Profil bearbeiten (YAML)
incus profile edit mein-webserver-profil

# Profil mit Limits
incus profile set mein-webserver-profil limits.memory=2GiB
incus profile set mein-webserver-profil limits.cpu=2

# Profil auf bestehende Instanz anwenden
incus profile add mein-container mein-webserver-profil

# Profil von Instanz entfernen
incus profile remove mein-container mein-webserver-profil

# Container mit Profil starten
incus launch images:debian/12 mein-container \
  --profile default \
  --profile mein-webserver-profil

Snapshots

# Snapshot anlegen
incus snapshot mein-container snapshot-20260630
incus snapshot mein-container mein-aktueller-stand  # kürzerer Name

# Alle Snapshots anzeigen
incus list snapshots
incus info mein-container                            # Snapshots im Info-Block

# Snapshot rückgängig machen (Instanz zurücksetzen)
incus restore mein-container snapshot-20260630

# Snapshot als neuen Container starten
incus copy mein-container/snapshot-20260630 neuer-container

# Snapshot löschen
incus delete mein-container/snapshot-20260630

Dateitransfer

# Datei in Container kopieren
incus file push ./config.yml mein-container/etc/config.yml
incus file push ./backup.sql mein-container/tmp/

# Datei aus Container holen
incus file pull mein-container/var/log/nginx/access.log ./access.log

# Datei rekursiv kopieren (ganzer Ordner)
incus file push ./build/ mein-container/var/www/ -r
incus file pull mein-container/var/log/ -r ./logs/

# Dateirechte setzen beim Pushen
incus file push --gid 1000 --uid 1000 config.yml \
  mein-container/etc/config.yml

Ressourcen-Limits

Limits werden direkt an der Instanz oder über ein Profil gesetzt.

incus config set mein-container limits.memory=1GiB
incus config set mein-container limits.memory=512MiB
incus config set mein-container limits.cpu=2
incus config set mein-container limits.cpu.allowance=50%       # CPU-Zeit
incus config set mein-container limits.disk.priority=5
incus config set mein-container limits.processes=100

# Limits anzeigen
incus config show mein-container

Umgebungsvariablen

# Setzen (beim Start)
incus launch images:debian/12 mein-container \
  --config environment.MY_VAR=wert

# Nachträglich (erfordert Neustart)
incus config set mein-container environment.MY_VAR=wert
incus restart mein-container

Storage Pools

# Speicher-Pools anzeigen
incus storage list

# Pool-Details
incus storage show default

# Storage-Volume anlegen (separates Volume)
incus storage volume create default mein-volume 10GiB

# Volume an Container binden
incus config device add mein-container mein-volume disk \
  pool=default \
  source=mein-volume \
  path=/mnt/data

# Volume-Snapshots
incus storage volume snapshot default mein-volume snap-1
incus storage volume restore default mein-volume snap-1

Projekte

Projekte trennen Umgebungen innerhalb einer Incus-Instanz.

# Projekte anzeigen
incus project list

# Projekt erstellen
incus project create mein-projekt

# Projekt wechseln
incus project switch mein-projekt

# Container im anderen Projekt starten
incus --project mein-projekt launch images:debian/12 container-1

# Projekt löschen
incus project delete mein-projekt

Netzwerke

# Managed Networks anzeigen
incus network list
incus network show incusbr0

# Bridge-Netzwerk anlegen
incus network create mein-netz \
  --type=bridge \
  ipv4.address=10.100.0.1/24 \
  ipv4.nat=true

# Netzwerk löschen
incus network delete mein-netz

Export / Import

# Backup als tar-Archiv
incus export mein-container mein-container-backup.tar.gz

# Backup inklusive Snapshots
incus export mein-container mein-container-backup.tar.gz \
  --instance-only                                           # ohne Snapshots

# Import
incus import mein-container-backup.tar.gz

Config-Tricks

# Vollständige Konfiguration einer Instanz anzeigen
incus config show mein-container
incus config show mein-container --expanded          # inkl. Profile

# Container im Texteditor bearbeiten (YAML)
incus config edit mein-container

# Instanz automatisch starten lassen
incus config set mein-container boot.autostart=true
incus config set mein-container boot.autostart.priority=100
incus config set mein-container boot.autostart.delay=5

# Container-Hostname ändern
incus exec mein-container -- hostnamectl set-hostname neuer-name

Kurzfassung der wichtigsten Pfade

Wofür Befehl
Container starten incus launch images:debian/12
VM starten incus launch images:debian/12 --vm
Shell incus exec -- bash
Liste incus list
Stop incus stop
Delete incus delete
Snapshot incus snapshot
Restore incus restore
File rein incus file push /
File raus incus file pull /
Limits setzen incus config set limits.memory=
Proxy-Device incus config device add proxy listen=... connect=...
Disk-Device incus config device add disk source=... path=...
Profil anwenden incus profile add