Autostart of lxd containers failing

Hi
i am running two containers with gui applications both of which have boot.autostart set to true, one with priority 100 and other with priority 99. The container with lowest priority is running fine but the other container is stopped. if i reverse the priorities the same thing happens. let me know if any extra info is needed.
Thanks in advance

When LXD tries to start a GUI container, it is instructed to make available the X11 Unix socket from the host to the container. But when you have just booted the computer, LXD is fast enough to load and start the containers, while you have not logged in yet into the system. Therefore, when LXD starts the GUI containers, there is no X11 socket yet available. Due to this, LXD is unable to pass the socket to the container and does not start the container at this time.

In such a case, it makes sense to somehow start the GUI containers as soon as you have logged into the desktop. Because anyway you would need X to be running to launch the GUI application.

Okay understood, is there any way in lxd to delay the start of the first container itself ?

There is the key boot.autostart.delay. See https://lxd.readthedocs.io/en/latest/containers/ for more.

If your container is called mycontainer, then the following will enable autostart, then set the container to start after 30 seconds (after the LXD service start),

lxc config set mycontainer boot.autostart 1
lxc config set mycontainer boot.autostart.delay 60

Obviously, this would make sense if you enable autologin on your desktop, so that you can estimate a good repeatable delay. You may use some external script to check whether you got it right, and if not, restart the container.

However, if you add anyway some external script, you could avoid dealing with the autostart because the script would set the socket anyway.

How does your container GUI app start? Does it start automatically from within the container?
My preference would be to just do a lxc start mycontainer in your system as soon as you autologin into the desktop. If the container somehow is already started, then lxc start mycontainer has no effect.

Enabled auto login and made the delay as 0 for both containers and set priorities as 100 and 99 ,containers start as expected but now i see a delay of more than 60 seconds after complete boot up of the system , is this expected from lxd? and is there any way to reduce this ? like using scripts as you mentioned.

The priorities have to do with the order that the containers will start.
You were supposed to the set the delay to, let’s say 60, but you set it to 0 and still the containers take about 60 seconds to start? This does not make sense.
Can you post the output of lxc config show mycontainer?

I asked you how you launch the GUI application in the container. Do you do this somehow automatically or do you start it by hand?

I am starting them as a service , so that as soon as i start my container the app comes up.

Below is the config of the two containers

it@it-ThinkPad-T430:~$ lxc config show gui1804
architecture: i686
config:
  boot.autostart: "true"
  boot.autostart.delay: "0"
  boot.autostart.priority: "100"
  volatile.base_image: 8d6bf6140615c765a42c018645019074e1566d74ad25561fee4c174d2c0a8782
  volatile.eth0.hwaddr: 00:16:3e:4a:69:ac
  volatile.idmap.base: "0"
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":true,"Isgid":false,"Hostid":166537,"Nsid":1001,"Maprange":64535},{"Isuid":false,"Isgid":true,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":false,"Isgid":true,"Hostid":166537,"Nsid":1001,"Maprange":64535}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":true,"Isgid":false,"Hostid":166537,"Nsid":1001,"Maprange":64535},{"Isuid":false,"Isgid":true,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":false,"Isgid":true,"Hostid":166537,"Nsid":1001,"Maprange":64535}]'
  volatile.last_state.power: RUNNING
devices:
  root:
    path: /
    type: disk
ephemeral: false
profiles:
- default
- gui
stateful: false
description: ""
it@it-ThinkPad-T430:~$ lxc config show gui1804S
architecture: i686
config:
  boot.autostart: "true"
  boot.autostart.delay: "0"
  boot.autostart.priority: "99"
  volatile.base_image: 8d6bf6140615c765a42c018645019074e1566d74ad25561fee4c174d2c0a8782
  volatile.eth0.hwaddr: 00:16:3e:8d:c6:3b
  volatile.idmap.base: "0"
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":true,"Isgid":false,"Hostid":166537,"Nsid":1001,"Maprange":64535},{"Isuid":false,"Isgid":true,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":false,"Isgid":true,"Hostid":166537,"Nsid":1001,"Maprange":64535}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":true,"Isgid":false,"Hostid":166537,"Nsid":1001,"Maprange":64535},{"Isuid":false,"Isgid":true,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":false,"Isgid":true,"Hostid":166537,"Nsid":1001,"Maprange":64535}]'
  volatile.last_state.power: RUNNING
devices:
  root:
    path: /
    type: disk
ephemeral: false
profiles:
- default
- gui
stateful: false
description: ""

Is that a systemd unit? Because, if it is so, then you can set a dependency for this unit to start as soon as your system starts up the desktop.
See tightvnc - How to set a systemd unit to start after loading the desktop? - Unix & Linux Stack Exchange for more.

You mention that even when you boot.autostart.delay: "0", the container starts after 60 seconds. If you can describe a minimal working example that exhibits this behavior, you can file a bug report at Issues · lxc/incus · GitHub