}

How to Autostart LXC Container at boot

Created:

Introduction

In this short guide we will explain how to setup a LXC container at boot.

Proxmox solution

In proxmox you can enable the "Start at boot" option by double cliking on it:

Proxmox boot option

Ubuntu/Debian without proxmox

All your containers configuration are saved in the directory /var/lib/lxc/name/config where name is the name of the container.

lxc config set container_name boot.autostart true

You can specify the order of bootig with the option lxc.start.order:

lxc config set container_name boot.priority 0 # will have the order 0, lower first.

You can check the container setting by using the get:

lxc config get container_name boot.priority

If you are using proxmox the lxc command is not available.

List boot options of all containers

You can use the following script to list all boot relevant options

#!/bin/bash
echo 'The current values of each vm boot parameters:'
for c in db_vm nginx_vm memcache_vm
do
   echo "*** VM: $c ***"
   for v in boot.autostart boot.autostart.priority boot.autostart.delay 
   do
      echo "Key: $v => $(lxc config get $c $v)"
   done
      echo ""
done