Lxd: How to write .yaml / .sh files to configure and deploy containers similarly to docker recipes (run commands upon container initiation)

Created on 18 Jun 2017  路  3Comments  路  Source: lxc/lxd

How to deploy containers in a similar way to docker recipes.

For example how to:

  • specify all the container details (shared/mounted devices, network, etc)
  • specify what commands to run upon initial start

From doing research there appears to be an option to configure the containers using a yaml file: https://askubuntu.com/questions/617865/is-there-a-way-to-configure-lxd-containers-with-cloud-config-at-provision-time

The yaml file was also mentioned in this tutorial under the "Image metadata" heading: https://stgraber.org/2016/03/30/lxd-2-0-image-management-512/

Unfortunately that tutorial did not cover how to deploy the lxc containers using yaml files (and how to format the files).

The above are related to deploying lxd containers as mentioned here: https://stackoverflow.com/questions/44456522/how-to-automate-application-deployment-when-using-lxd-containers

Most helpful comment

You're welcome to script around "lxc exec" and the various "lxc file" commands. There is however no way in LXD to have it run the equivalent of a DockerFile. Most people will use their own deployment tools for such things, be it Ansible, Puppet, ...

To roll your own thing from a clean host, you could:

  • Use "lxd init --preseed" to setup the LXD daemon itself
  • Use "lxc init" rather than "lxc launch" to create the container without starting it
  • Use "lxc config edit" to apply a full container configuration in one shot (it reads yaml from stdin)
  • Then start the container and use "lxc exec" to run whatever you want inside of it

All 3 comments

I've noticed the documentation shows the configuration format: https://github.com/lxc/lxd/blob/master/doc/preseed.md

How to specify which commands to run when the container is first created and initiated?

You're welcome to script around "lxc exec" and the various "lxc file" commands. There is however no way in LXD to have it run the equivalent of a DockerFile. Most people will use their own deployment tools for such things, be it Ansible, Puppet, ...

To roll your own thing from a clean host, you could:

  • Use "lxd init --preseed" to setup the LXD daemon itself
  • Use "lxc init" rather than "lxc launch" to create the container without starting it
  • Use "lxc config edit" to apply a full container configuration in one shot (it reads yaml from stdin)
  • Then start the container and use "lxc exec" to run whatever you want inside of it

The yaml that's valid for "lxc config edit" is the same you'd see when doing "lxc config show" against an existing container.

Was this page helpful?
0 / 5 - 0 ratings