Specifically, with the CLI tools- not openstack.
I'm looking at what a local dev setup with lxd might look like but am coming up empty handed when it comes to configuring new containers.
Are there any idiomatic (or otherwise) ways to configure lxd containers? Should I be looking at something more immutable like docker images?
Thanks. Any resources or pointers would be appreciated.
So there are multiple ways you can do so, either directly for a container:
Or even shorter:
Or through a profile:
I had a slightly more specific question than the OP but it took me a while to work out what I was doing wrong. I thought I would post it here to help anyone else getting similarly stumped.
I wanted static networking settings for an LXC/LXD Ubuntu 16.04 container hosted on Ubuntu 16.04. I started by trying what Stéphane wrote but it wasn't working. All I ended up with was the default DHCP-attempting container with an IPv6 link local, as there is no DHCP being served in my configuration.
My initial YAML looked (something) like the following (taken from the cloud-init docs).
And I was loading this into
user.user-data
as described above.It wasn't until I found Stéphane's documentation in the LXC/LXD source that I realised I needed to load that value into
user.network-config
.So my final YAML looked (something) like this.
Then I loaded this into
user.network-config
instead.It seems like I will need to keep two different files per container: one for network settings to load to
user.network-config
; and one for other config to load intouser.user-data
unless I can find a way of using a single file for everything.Another problem I found which wasn't obvious to me at all was trying to configure non-network components automatically.
The following YAML applied with the command above (despite looking correct using
lxc config show CONTAINER
) did not create anything inside my container.The clue buried away in User Data Input Formats, item 5: Cloud Config Data reads:
I don't believe this documentation is very clear. I could not get anything to work using the "Content-Type: text/cloud-config" form but I did find if you put
#cloud-config
on the first line, the YAML is parsed. I can only assume something isn't quite right, either my understanding, or someone's programming. It makes no sense to me that YAML you've explicitly loaded as the value of the keyuser.user-data
should be used as anything other than cloud configuration data. Why else would anyone do that if it wasn't meant to be cloud configuration, and therefore why would a comment (which doesn't even use the normal shebang syntax) be required?So, nonsense aside, the syntax which worked for
user.user-data
is:One liner I went with today, this one sets it in the default profile for new containers:
echo -e "#cloud-config\nssh_authorized_keys:\n - $(cat ~/.ssh/id_rsa.pub)" | lxc profile set default user.user-data -
This one sets it in an existing container, but beware it will not work on containers that already booted as the SSH key stuff only gets done on first boot:
echo -e "#cloud-config\nssh_authorized_keys:\n - $(cat ~/.ssh/id_rsa.pub)" | lxc config set CONTAINER_NAME user.user-data -