9.5 KiB
(first-steps)=
First steps with Incus
This tutorial guides you through the first steps with Incus. It covers installing and initializing Incus, creating and configuring some instances, interacting with the instances, and creating snapshots.
After going through these steps, you will have a general idea of how to use Incus, and you can start exploring more advanced use cases!
Install and initialize Incus
-
Install the Incus package
Incus is available on most common Linux distributions.
For detailed distribution-specific instructions, refer to {ref}
installing. -
Allow your user to control Incus
Access to Incus in the packages above is controlled through two groups:
incusallows basic user access, no configuration and all actions restricted to a per-user project.incus-adminallows full control over Incus.
To control Incus without having to run all commands as root, you can add yourself to the
incus-admingroup:sudo adduser $USER incus-admin newgrp incus-adminThe
newgrpstep is needed in any terminal that interacts with Incus until you restart your user session. -
Initialize Incus
If you are migrating from an existing LXD installation, skip this step and refer to {ref}`server-migrate-lxd` instead.Incus requires some initial setup for networking and storage. This can be done interactively through:
incus admin initOr a basic automated configuration can be applied with just:
incus admin init --minimalIf you want to tune the initialization options, see {ref}
initializefor more information.
Launch and inspect instances
Incus is image based and can load images from different image servers. In this tutorial, we will use the official image server.
You can list all images that are available on this server with:
incus image list images:
See {ref}images for more information about the images that Incus uses.
Now, let's start by launching a few instances.
With instance, we mean either a container or a virtual machine.
See {ref}containers-and-vms for information about the difference between the two instance types.
For managing instances, we use the Incus command line client incus.
-
Launch a container called
firstusing the Debian 12 image:incus launch images:debian/12 firstLaunching this container takes a few seconds, because the image must be downloaded and unpacked first. -
Launch a container called
secondusing the same image:incus launch images:debian/12 secondLaunching this container is quicker than launching the first, because the image is already available. -
Copy the first container into a container called
third:incus copy first third -
Launch a VM called
debian-vmusing the Debian 12 image:incus launch images:debian/12 debian-vm --vmEven though you are using the same image name to launch the instance, Incus downloads a slightly different image that is compatible with VMs. -
Check the list of instances that you launched:
incus listYou will see that all but the third container are running. This is because you created the third container by copying the first, but you didn't start it.
You can start the third container with:
incus start third -
Query more information about each instance with:
incus info first incus info second incus info third incus info debian-vm -
We don't need all of these instances for the remainder of the tutorial, so let's clean some of them up:
-
Stop the second container:
incus stop second -
Delete the second container:
incus delete second -
Delete the third container:
incus delete thirdSince this container is running, you get an error message that you must stop it first. Alternatively, you can force-delete it:
incus delete third --force
-
See {ref}instances-create and {ref}instances-manage for more information.
Configure instances
There are several limits and configuration options that you can set for your instances.
See {ref}instance-options for an overview.
Let's create another container with some resource limits:
-
Launch a container and limit it to one vCPU and 192 MiB of RAM:
incus launch images:debian/12 limited --config limits.cpu=1 --config limits.memory=192MiB -
Check the current configuration and compare it to the configuration of the first (unlimited) container:
incus config show limited incus config show first -
Check the amount of free and used memory on the parent system and on the two containers:
free -m incus exec first -- free -m incus exec limited -- free -mThe total amount of memory is identical for the parent system and the first container, because by default, the container inherits the resources from its parent environment. The limited container, on the other hand, has only 192 MiB available. -
Check the number of CPUs available on the parent system and on the two containers:
nproc incus exec first -- nproc incus exec limited -- nprocAgain, the number is identical for the parent system and the first container, but reduced for the limited container. -
You can also update the configuration while your container is running:
-
Configure a memory limit for your container:
incus config set limited limits.memory=128MiB -
Check that the configuration has been applied:
incus config show limited -
Check the amount of memory that is available to the container:
incus exec limited -- free -mNote that the number has changed.
-
-
Depending on the instance type and the storage drivers that you use, there are more configuration options that you can specify. For example, you can configure the size of the root disk device for a VM:
-
Check the current size of the root disk device of the Debian VM:
:input: incus exec debian-vm -- df -h Filesystem Size Used Avail Use% Mounted on /dev/root 9.6G 1.4G 8.2G 15% / tmpfs 483M 0 483M 0% /dev/shm tmpfs 193M 604K 193M 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 50M 14M 37M 27% /run/incus_agent /dev/sda15 105M 6.1M 99M 6% /boot/efi -
Override the size of the root disk device:
incus config device override debian-vm root size=30GiB -
Restart the VM:
incus restart debian-vm -
Check the size of the root disk device again:
:input: incus exec debian-vm -- df -h Filesystem Size Used Avail Use% Mounted on /dev/root 29G 1.4G 28G 5% / tmpfs 483M 0 483M 0% /dev/shm tmpfs 193M 588K 193M 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 50M 14M 37M 27% /run/incus_agent /dev/sda15 105M 6.1M 99M 6% /boot/efi
-
See {ref}instances-configure and {ref}instance-config for more information.
Interact with instances
You can interact with your instances by running commands in them (including an interactive shell) or accessing the files in the instance.
Start by launching an interactive shell in your instance:
-
Run the
bashcommand in your container:incus exec first -- bash -
Enter some commands, for example, display information about the operating system:
cat /etc/*release -
Exit the interactive shell:
exit
Instead of logging on to the instance and running commands there, you can run commands directly from the host.
For example, you can install a command line tool on the instance and run it:
incus exec first -- apt-get update
incus exec first -- apt-get install sl -y
incus exec first -- /usr/games/sl
See {ref}run-commands for more information.
You can also access the files from your instance and interact with them:
-
Pull a file from the container:
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 container:
incus file push hosts first/etc/hosts -
Use the same mechanism to access log files:
incus file pull first/var/log/syslog - | lessPress `q` to exit the `less` command.
See {ref}instances-access-files for more information.
Manage snapshots
You can create a snapshot of your instance, which makes it easy to restore the instance to a previous state.
-
Create a snapshot called "clean":
incus snapshot create first clean -
Confirm that the snapshot has been created:
incus list first incus info first`incus list` shows the number of snapshots. `incus info` displays information about each snapshot. -
Break the container:
incus exec first -- rm /usr/bin/bash -
Confirm the breakage:
incus exec first -- bashYou do not get a shell, because you deleted the `bash` command. -
Restore the container to the state of the snapshot:
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
See {ref}instances-snapshots for more information.