# Incus Profile Tricks (Power shortcuts to creating containers)

**URL:** https://discussion.scottibyte.com/t/incus-profile-tricks-power-shortcuts-to-creating-containers/418
**Category:** Uncategorized
**Created:** [May 20, 2024, 10:00pm UTC](https://discussion.scottibyte.com/t/incus-profile-tricks-power-shortcuts-to-creating-containers/418 "2024-05-20T22:00:42Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![scott](https://discussion.scottibyte.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://discussion.scottibyte.com/u/scott)
#### Post date: [May 20, 2024, 10:00pm UTC](https://discussion.scottibyte.com/t/incus-profile-tricks-power-shortcuts-to-creating-containers/418/1 "2024-05-20T22:00:43Z")

</div>

When you install an Incus server you get the “default” profile and in “Incus Containers Step by Step” we created the bridgeprofile. Today we learn how to use profiles as shortcuts to create containers and much more.

The default profile defines the eth0 device to be bridged via incusbr0 (or lxdbr0 if you upgraded from a LXD Server). The bridge places containers on an internal NAT network and that’s one reason we created the bridgeprofile to offer containers on your LAN with their own addresses. The default profile also defines the root file system for your containers and the storage for them to be in the default storage pool.

You can list the profiles that you have defined on your incus server. I have several profiles.

```auto
incus profile list

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/f/fe908d1dfc6c64fd5ea0f6156393a2598278c56b.png)

You can edit an existing incus profile.

```auto
incus profile edit default

```

Let’s launch a new container named “test1” that will have an internal NAT address. This means that this container is normally unreachable from other computers on your LAN.

```auto
incus launch images:ubuntu/24.04 test1 -c boot.autostart=true 

```

Let’s go perform the updates on this new container. Note that this is another way to execute commands in a container without going into the shell.

```auto
incus exec test1 -- apt update 

```

Let’s install the Apache Web Server in the container:

```auto
incus exec test1 -- apt install apache2 -y

```

Since the test1 container has a NAT address, it is not reachable by other computers on your network.

We can fix that by adding a proxy from a port on your incus server to the port for the Apache Web server running inside the container. This is similar to port mappings used in docker containers.

Lets create a new profile.

```auto
incus profile create proxy-8080

```

Next, I am adding the mapping from the Apache web server inside of the container which is running at TCP port 80 to listen on the incus server at port 8080.

```auto
incus profile device add proxy-8080 hostport8080 proxy listen=tcp:0.0.0.0:8080 connect=tcp:127.0.0.1:80

```

You can list out this profile with this command:

```auto
incus profile show proxy-8080

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/6/659b4b2a8e8d383b9e4b6ebc4dba69f4fedcf5bf.png)

At this point, the Apache Web Server is only reachable from the NAT address while on the Incus server. This means that Apache cannot be accessed by other computers on your network.

To fix this, add the profile we just created to the test1 container:

```auto
incus profile add test1 proxy-8080

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/8/8bf7065bd26dd1b5d343d2201b28b8cdd7549350.png)

So now, I can reach the Apache server at the address of my server (172.16.1.225) at port 8080 in virtue of the proxy even though my container does not have its own LAN address.

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/f/fc66e81d660194632bab9f4a727341763ed7e80a.jpeg)

Next, we are going to create a profile that:

1. Creates a Container in a pool named pool2.
2. Creates that container bridged to the LAN with its own address.

So, this effectively does what the bridgeprofile does but also adds using this new pool.

Create a folder for a files based storage pool:

```auto
mkdir -p /home/scott/pool2

```

Create a new storage pool:

```auto
incus storage create pool2 dir source=/home/scott/pool2

```

Create a new profile.

```auto
incus profile create pool2profile

```

Add the “bridging” definition to the profile:

```auto
incus profile device add pool2profile eth0 nic name=eth0 nictype=bridged parent=bridge0

```

Add the definition to use pool2 for any containers that use this profile:

```auto
incus profile device add pool2profile root disk path=/ pool=pool2

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/e/e8c45f88585ef6fdacde7eb88d737167dcc0d967.png)

Now I can launch a new container named “test2” that is bridged to its own LAN address and the container is created in the new pool2 storage pool.

```auto
incus launch images:ubuntu/24.04 test2 -p pool2profile -c boot.autostart=true 

```

The value of using profiles to accomplish this is that you don’t have to remember all of the separate commands.

The “incus list” command shows that the new container test2 has an address on my LAN.

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/9/948537a1823759e4afc97f9be47c903f2a08f080.jpeg)

The “incus storage list” command and the “incus storage show pool2” command show that pool2 has two objects in it and one of them is the container test2 and the other is the pool2profile.

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/2/2f3ad70ebf2826a5b0b3029b6fe8ca8cf3c2b5a2.png)

This means that all new containers that you apply this profile to will have a LAN address and be stored in pool2.

The device “eth0” inside your incus containers is a virtual network interface card (NIC). Let’s create a new profile to add a NIC named eth1.

```auto
incus profile create newnic

```

Let’s add the attributes to bridge the new eth1 device to an address on the LAN.

```auto
incus profile device add newnic eth1 nic name=eth1 nictype=bridged parent=bridge0

```

Create a shell to the test2 container:

```auto
incus shell test2

```

Install net-tools.

```auto
apt install net-tools -y

```

List the network interfaces.

```auto
ifconfig

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/2/26a45d95bf71c550e675f327f728f876533e5cf4.jpeg)

Exit back to the incus server.

```auto
exit

```

Add the newnic profile to the test2 container.

```auto
incus profile add test2 newnic

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/5/5f4ba3970b3b04bc6d7ba419d9de6aba987ba364.png)

Shell back into the container and move to the netplan folder.

```auto
incus shell test2
cd /etc/netplan

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/c/c89d72b3f37598a2aa7f239489b123b13beda86a.png)

Edit the netplan configuration file.

```auto
nano 10-lxc.yaml

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/c/c8abb3da9fc8be8acc5e0ea69e5e5b65891aebbf.png)

Add a section for the eth1 device as follows:

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/7/7617c2a7a84d40743d9917a527dceaa6c5645741.png)

Do a CTRL O and Enter to save the file and a CTRL X to exit the nano editor.

Apply the new settings:

```auto
netplan apply

```

Examine the new network settings and you should now have an eth1 device.

```auto
ifconfig

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/1/1b4dd9ad7f20d702b51b5912dc7f91e9702eefdc.jpeg)

Exit the container.

```auto
exit

```

List your containers and note that the test2 container has an address for both eth0 and eth1.

```auto
incus list

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/d/dda92d0ca0152f55766b5764548281353f8beef1.jpeg)

We can remove the eth1 command also.

```auto
incus profile remove test2 newnic

```

If we list the containers again, note that test2 no longer has an eth1 device.

```auto
incus list

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/d/d59558303d6f08d08a13511f1818aeed401291ff.png)

On my router, I have VLAN 80 being managed. Let’s create a profile for vlan80.

```auto
incus profile create vlan80

```

Assign the attributes to the vlan80 profile to assign an address in VLAN 80.

```auto
incus profile device add vlan80 eth0 nic name=eth0 nictype=macvlan vlan=80 parent=bridge0

```

Add the vlan80 profile to the test2 container:

```auto
incus profile add test2 vlan80

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/8/8e25336f4808ecef923e38941d2185318550578b.png)

List the containers and see that the test2 container has an address on VLAN 80:

```auto
incus list

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/7/7ceedada622953f5cf1035c3528f2cc58dfda37e.png)

Likewise, if we remove the vlan80 profile from the test2 container, it reverts back to its LAN address.

```auto
incus profile remove test2 vlan80

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/5/586a7e9c186fb92f9221708f080665890afa5d3e.jpeg)

Now, for something completely different, create a new profile:

```auto
incus profile create snap-hourly

```

Let’s apply the attributes to perform hourly container snapshots for any container using this profile.

```auto
incus profile set snap-hourly snapshots.schedule "@hourly"

```

Let’s add a pattern template for naming our Snapshots with the prefix “Hourly-” followed by a date/time stamp.

```auto
incus profile set snap-hourly snapshots.pattern "Hourly-{{ creation_date|date:'01-02-2006_15:04' }}"

```

Let’s set our Snapshots to expire every four hours meaning that we will have at most four (4) snapshots.

```auto
incus profile set snap-hourly snapshots.expiry "4H"

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/e/e2db211b169a0ebe19a6b8fa1dc35a9272ff9e13.png)

Let’s apply these rules to our test2 container:

```auto
incus profile add test2 snap-hourly

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/a/aa7aeb903d7e62fd7ba7995e48c2b0ec3ca5f633.png)

After I waited five hours, I had the most recent four snapshots named according to my pattern definition.

```auto
incus snapshot list test2

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/7/739d040bab7bd7e0207a46b41a2db611a31cec4e.png)

Profiles are very handy to apply complex settings to containers simply.
