Autostarting LXC containers
By default, LXC containers do not start after a server reboot. To change that, we can use the lxc-autostart
tool and the containers configuration file:
To demonstrate this, let's create a new container first:
root@ubuntu:~# lxc-create --name autostart_container --template ubuntu root@ubuntu:~# lxc-ls -f NAME STATE AUTOSTART GROUPS IPV4 IPV6 autostart_container STOPPED 0 - - - root@ubuntu:~#
Next, add the
lxc.start.auto
stanza to its config file:root@ubuntu:~# echo "lxc.start.auto = 1" >> /var/lib/lxc/autostart_container/config root@ubuntu:~#
List all containers that are configured to start automatically:
root@ubuntu:~# lxc-autostart --list autostart_container root@ubuntu:~#
Now we can use the
lxc-autostart
command again to start all containers configured to autostart, in this case just one:root@ubuntu:~# lxc-autostart --all ...