3

I normally create containers with:

lxc-create -n mycontainer -t debian

However I want to bake a few items into that "debian" default template.

  1. New user with my ssh key, can sudo without a password.
  2. Have python installed.

Basically this is the bare bones needed for ansible. I then want to provision my container via ansible from there.

However, I can't find any information on how to customize an lxc template. I have seen a few tutorials about creating a template from scratch, but that is not what I want to do. I want to simply customize an existing template.

OS is debian 8, both host and guest.

Thanks!

cat pants
  • 753
  • 5
  • 23
  • 38

1 Answers1

2

If you want to add a package, edit:

/usr/share/lxc/templates/lxc-debian

and search for download_debian(). Add your package to that section along with the other packages (I see ifupdown, locales, etc). If you make changes to the package list, you will need to clear the cache. I do that by doing:

rm -rf /var/cache/lxc/debian/

Of course the next container you create will take some time to download packages.

If you want to run a command in the container, add the following:

chroot $rootfs <command>

at the end of configure_debian(). You can also copy files from the host into $rootfs as well.

cat pants
  • 753
  • 5
  • 23
  • 38