How to auto start LXD containers VM at boot time in Linux

How to auto start LXD containers VM at boot time in Linux

To start an LXD container automatically at boot time, you can use the following steps:

  1. Start the container manually using the lxc start command. For example:
‮ refer‬to:lautturi.com
lxc start mycontainer
  1. Set the container to autostart using the lxc config set command. For example:
lxc config set mycontainer boot.autostart true
  1. Check that the container is set to autostart using the 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.

Created Time:2017-10-28 21:38:58  Author:lautturi