Managing container creation process


Per a previous topic, I am now running a container per each ‘service’ that my server needs to run (samba, plex, db, dns-server, etc). I currently have 10 containers running just fine :slight_smile:

I have realised that for each configuration, I kind of do a lot of the same process:

  1. Configure the static IP
  2. Install package A and configure it in a certain way
  3. Copy a configuration fail into a specific place on the container and restart the service

I then might do some container specific stuff

  1. Install packages B, C and D unique to this container
  2. Do some container specific configuration
  3. Maybe do some stuff on the host (i.e. create a system user) then bind map a drive or so
  4. Perhaps download a tarball from github and run a script

That got me thinking, it would be great to do all this by configuration; for example if I had a series of text based configurations/scripts that I run to create each container. I could quickly spin up the containers if I ever need to:

  • Disaster recovery
  • Upgrade to new OS by launching a new container and configuring per the script
  • Refining the container installation process

I think this is generally known as container orchestration (?) I also thing cloudconfig could do some of what I require, but not all (for example, could I have cloudconfig entries in multiple LXD profiles and then apply all them profiles at container creation time?).

Is there a best way forward for someone like me that is just running a home-based server and doesn’t need a full data-centre solution?


cloud-config does all the things you list,

You could also mount folders into your containers for your config files / data, when you want to upgrade OS you just have to apply the profile to the new image

if you put this under user.user-data on a profile and apply that profile to a container it will install samba and link your config file (samba is bad example for this because you wouldn’t replace a samba server in the same way you would a webserver - its more a pet than cattle)


 - samba

 - mv /etc/samba/smb.conf{,.orig}
 - ln /some/mount/path/smb.conf /etc/samba/smb.conf
 - Any arbitrary bash command you imagine 

You can only apply user.user-data from one profile (due to the complexities of merging them) but you could also use user.vendor-data to apply additional settings if they couldn’t be covered in one cloud-config file (but I guess I would question why not - some programs (I know mine does) uses vendor-data some times so it may cause compatibility issues)

As far as I’m aware there is no orchestration tools specifically for LXD, but ive seen other people using
Ansible & the Kubernetes shim which may give you more traditional tools