LXC containers randomly stop getting ipv4 dhcp addresses

I can help you with Incus (a continuation of LXD).

Here is me launching 100 containers.

$ /opt/incus/bin/incus-benchmark launch --count 100 images:alpine/3.19/cloud
Test environment:
  Server backend: incus
  Server version: 0.5.1
  Kernel: Linux
  Kernel tecture: x86_64
  Kernel version: 6.5.0-15-generic
  Storage backend: zfs
  Storage version: 2.1.5-1ubuntu6~22.04.2
  Container backend: lxc | qemu
  Container version: 5.0.3 | 8.2.1

Test variables:
  Container count: 100
  Container mode: unprivileged
  Startup mode: normal startup
  Image: images:alpine/3.19/cloud
  Batches: 8
  Batch size: 12
  Remainder: 4

[Feb  3 00:17:50.038] Importing image into local store: 5fc72e9ed16cc3f3db367a3e97d7726d796a6450813446bde06f7f586b4de7d5
[Feb  3 00:17:54.611] Found image in local store: 5fc72e9ed16cc3f3db367a3e97d7726d796a6450813446bde06f7f586b4de7d5
[Feb  3 00:17:54.611] Batch processing start
[Feb  3 00:18:02.864] Processed 12 containers in 8.253s (1.454/s)
[Feb  3 00:18:10.331] Processed 24 containers in 15.720s (1.527/s)
[Feb  3 00:18:25.662] Processed 48 containers in 31.051s (1.546/s)
[Feb  3 00:18:57.019] Processed 96 containers in 62.408s (1.538/s)
[Feb  3 00:19:01.481] Batch processing completed in 66.871s

All containers are named automatically, with the format benchmark-%03d.

I list them with the following. The benchmark- is used as a filter. incus list matches whatever is given as argument in the end. In my case, all containers got IPv4 and IPv6 address. So far, so good.

$ incus list benchmark-

I then delete the benchmark containers in one go. 100 containers gone in 24 seconds.
I hope you do not have any containers named benchmark-something :slight_smile:

$ /opt/incus/bin/incus-benchmark delete
...
[Feb  3 00:23:14.040] Batch processing completed in 23.902s

We have seen how to start many containers for our testing.

Disabling IPv6 is tricky. IPv6 is important. But if you insist,

  1. The GRUB method does not work in containers. You just want the containers not to have IPv6.
  2. The sysctl method for IPv6 does not appear to work.
  3. What works, is echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6 in the container.
  4. But sysctl and number 3 are the same. What gives?

Here is how to disable IPv6 in images:alpine/3.19/cloud. You can automate with cloud-init.

$ incus launch images:alpine/3.19/cloud alpine
Launching alpine
$ incus shell alpine
alpine:~# rc-update add sysctl default
 * service sysctl added to runlevel default
alpine:~# echo "net.ipv6.conf.all.disable_ipv6 = 1" | tee /etc/sysctl.d/10-disable-ipv6.conf
net.ipv6.conf.all.disable_ipv6 = 1
alpine:~# 
$ incus restart alpine
$ incus list alpine
+--------+---------+---------------------+------+-----------+-----------+
|  NAME  |  STATE  |        IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+--------+---------+---------------------+------+-----------+-----------+
| alpine | RUNNING | 10.10.10.44 (eth0) |      | CONTAINER | 0         |
+--------+---------+---------------------+------+-----------+-----------+
$