Skip to content

Instantly share code, notes, and snippets.

@erhangundogan
Last active August 13, 2025 21:02
Show Gist options
  • Save erhangundogan/898b793117e0b4abb1a0d9ff39e75f96 to your computer and use it in GitHub Desktop.
Save erhangundogan/898b793117e0b4abb1a0d9ff39e75f96 to your computer and use it in GitHub Desktop.
Incus

Incus

https://linuxcontainers.org/incus

Start

incus admin init

Some base lists

incus profile list
incus cluster list
incus network list
incus remote list
incus image list

Import

$ incus image list images: | more

Or specifically Alpine for arm64 (MacOS)

$ incus image list images:alpine arm64

Add existing network interface

$ incus network attach-profile vlanbr0 default

Download from remote

$ incus image copy images:4c307beb1d38 local:

# set alias for image
$ incus image alias create alpine/[email protected] 4c307beb1d38 --debug --verbose

Set password for alpine root

$ incus exec ruling-treefrog -- sh -c 'passwd'

# add user
$ lxc exec apache1 -- sudo --user ubuntu --login

Launch instance

# Alpine image
$ incus launch local:4c307beb1d38 --debug --console

# with alias
$ incus launch local:alpine/[email protected]

# ubuntu vm
$ incus launch ubuntu:24.04 my-vm --vm

# ubuntu container
$ incus launch ubuntu:24.04 my-container
$ incus launch images:alpine/edge alpine
$ incus launch images:debian/12 debian --vm

# with limits
$ incus launch images:ubuntu/24.04 limited -c limits.cpu=1 -c limits.memory=192MiB

Get info

$ incus info debian

Get config

$ incus config show limited

# show server resources
$ free -m
$ incus exec limited -- free -m

# check cpus available
$ nproc
$ incus exec limited -- nproc

# change resource while running 
$ incus config set limited limits.memory=128MiB

Access files

# Pull a file from the instance:
$ incus file pull first/etc/hosts .

# Add an entry to the file:
$ echo "1.2.3.4 my-example" >> hosts

# Push the file back to the instance:
$ incus file push hosts first/etc/hosts

# Use the same mechanism to access log files:
$ incus file pull first/var/log/syslog - | more
q

Snapshots

Incus supports creating and restoring instance snapshots.

# Create a snapshot called "clean":
$ incus snapshot create first clean

# Confirm that the snapshot has been created:
$ incus snapshot list first

# Break the instance:
$ incus exec first -- rm -Rf /etc /usr

# Confirm the breakage:
$ incus exec first -- bash

# Note that you do not get a shell, because you deleted the bash command.
# Restore the instance to the snapshotted state:
$ incus snapshot restore first clean

# Confirm that everything is back to normal:
$ incus exec first -- bash
$ exit

# Delete the snapshot:
$ incus snapshot delete first clean

Start/Stop/Delete

$ incus start debian
$ incus stop debian
$ incus delete debian 
$ incus delete debian --force

Storage

$ incus storage list
$ incus storage volume list local

# enlarge vm volume
$ incus config device override test-vm root size=20GiB

# Restart
$ incus restart test-vm

# We can create additional storage volumes in the default storage pool
$ incus storage volume create default mydisk size=10GB --type=block

# Attach new volume to the test-vm
$ incus storage volume attach default mydisk test-vm

Forward incus image ip

socat tcp-listen:8080,reuseaddr,fork TCP:10.0.3.17:80
# on ubuntu see if port 8443 is used
ss -tuln | grep 8443

API

unix.socket

$ curl --unix-socket /var/lib/incus/unix.socket incus/1.0

Here API calls when image launced with:

Exist console: +a q

GET http://unix.socket/1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment