Ubuntu 22.04 container loses IPv4 address in the absence of cloud-init

Host OS: Ubuntu 20.04
LXD snap latest/stable
Container image: Ubuntu 22.04
Networking: lxbr0 LXD bridge

Since I’m not using cloud-init, I purged the cloud-init package, and since this container is for a very limited access research project, I disabled apparmor.

However, after doing this I notice that whenever I reboot or stop/start the container, it loses its IPv4 address:

lxd-user@kerkyra:~$ lxc list
+------------+---------+------+------+-----------+-----------+
|    NAME    |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |
+------------+---------+------+------+-----------+-----------+
| ubuntu2204 | RUNNING |      |      | CONTAINER | 0         |
+------------+---------+------+------+-----------+-----------+

Re-running netplan apply resolves the issue:

lxd-user@kerkyra:~$ lxc exec ubuntu2204 -- netplan apply
WARNING:root:Cannot call Open vSwitch: ovsdb-server.service is not running.
lxd-user@kerkyra:~$ lxc list
+------------+---------+----------------------+------+-----------+-----------+
|    NAME    |  STATE  |         IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+------------+---------+----------------------+------+-----------+-----------+
| ubuntu2204 | RUNNING | 10.29.229.132 (eth0) |      | CONTAINER | 0         |
+------------+---------+----------------------+------+-----------+-----------+

Can someone explain what is going on here? Also, generally I use a host system bridge to spin up containers as ordinary hosts on the network, in which case I assign static IP addresses to containers. Does it even make sense to set a static IP address for a container attached to lxbr0? I realized I don’t recall ever setting this up. A reference to any available documentation would also be helpful. I’m a bit confused right now about how networking is working.

Hello Patrick,

I tried reproducing the issue but couldn’t. Could you share simple reproducer steps, please? Here’s what I tried:

$ lxc launch ubuntu-minimal-daily:22.04 c2
# c2 gets an IP
$ lxc exec c2 -- apt-get purge -Vy cloud-init
$ lxc restart c2
# c2 still gets an IP

On further investigation, it looks like this is not related to cloud-init:

lxd-user@kerkyra:~$ lxc launch ubuntu:22.04 u2
Creating u2
Starting u2
lxd-user@kerkyra:~$ lxc list
+------------+---------+----------------------+------+-----------+-----------+
|    NAME    |  STATE  |         IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+------------+---------+----------------------+------+-----------+-----------+
| u2         | RUNNING | 10.29.229.115 (eth0) |      | CONTAINER | 0         |
+------------+---------+----------------------+------+-----------+-----------+
| ubuntu2204 | RUNNING | 10.29.229.132 (eth0) |      | CONTAINER | 0         |
+------------+---------+----------------------+------+-----------+-----------+
lxd-user@kerkyra:~$ lxc restart u2
lxd-user@kerkyra:~$ lxc list
+------------+---------+----------------------+------+-----------+-----------+
|    NAME    |  STATE  |         IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+------------+---------+----------------------+------+-----------+-----------+
| u2         | RUNNING |                      |      | CONTAINER | 0         |
+------------+---------+----------------------+------+-----------+-----------+
| ubuntu2204 | RUNNING | 10.29.229.132 (eth0) |      | CONTAINER | 0         |
+------------+---------+----------------------+------+-----------+-----------+

When you restart and don’t get an IP, what does:

lxc network list-leases lxdbr0

Show?