To start an LXD container automatically at boot time, you can use the following steps:
lxc start
command. For example:lxc start mycontainer
lxc config set
command. For example:lxc config set mycontainer boot.autostart true
lxc config show
command. For example:lxc config show mycontainer | grep autostart
This should output the line "autostart: true".
Note: The container must be in the "RUNNING" state for the autostart setting to take effect.
Alternatively, you can create a systemd service to start the container at boot time. To do this, create a file in the /etc/systemd/system
directory with a name like "lxd-mycontainer.service" and the following contents:
[Unit] Description=LXD container: mycontainer After=network.target [Service] Type=simple ExecStart=/usr/bin/lxc start mycontainer ExecStop=/usr/bin/lxc stop mycontainer [Install] WantedBy=multi-user.target
Then enable and start the service using the following commands:
systemctl enable lxd-mycontainer systemctl start lxd-mycontainer
The container should now start automatically at boot time.