Getting Started

Getting Started #

Prerequisites #

lxd-compose doesn’t require libraries or tools, just an LXD instance to call.

Get LXD Compose #

lxd-compose is available as Mocaccino OS package and installable in every Linux distro through luet tool with these steps:

Installation #

$> curl | sudo sh # Install luet on your system
$> sudo luet install -y repository/mocaccino-extra-stable # Install Mocaccino Extra repository
$> sudo luet install -y app-emulation/lxd-compose # Install lxd-compose binary
$> sudo luet cleanup

Upgrade #

$> sudo luet upgrade

Create environment tree #

There isn’t a specific directory tree required to create an lxd-compose project but hereinafter is explained the best practices to start.

$> mkdir myproject && cd myproject
$> mkdir -p envs/files  # Create directory for static files (optional)
$> mkdir -p envs/groups # Create directory for containers groups (optional)
$> mkdir -p envs/vars   # Create directory for environment variables (optional)

The next step is create the lxd-compose configuration file. This file is using YAML format and is automatically read if it’s called .lxd-compose.yml.

$> echo "
  debug: false

  level: \"info\"
  runtime_cmds_output: true

# Define the directories list where load environments.
- ./envs
" > .lxd-compose.yml

Now, it’s time to create the project file ./envs/myproject.yml:

version: "1"

  engine: "mottainai"


  - name: "myproject1"
    description: "My First Project"

    # A fast way to define environments for template
      - envs:
          my_var: "value1"
            key: "xxx"
            foo: "baa"

      - name: "group1"
        description: "Group 1"

        # Define the LXD Remote to use and where
        # create the environment.
        connection: "local"
        # Define the list of LXD Profile to use
        # for create the containers
          - default

        # Create the environment container as ephemeral or not.
        ephemeral: true

          - name: node1
            image_source: "alpine/3.12"

              - "/bin/sh"
              - "-c"

            # List of commands executed just after the creation of the
            # container.

              - event: post-node-creation
                  - echo "Run container command ${my_var}"

              # Print node json
              - event: post-node-creation
                  - apk add curl
                  - curl --no-progress-meter | sh
                  - luet install repository/mocaccino-extra
                  - luet install utils/jq
                  - echo "${node}" | jq

And finally, deploy the project:

$> lxd-compose apply myproject1
Apply project myproject1
Searching image: alpine/3.12
For image alpine/3.12 found fingerprint 57a2e180cbb8b3daf21a51681232e88d145ebd8955a62ada48f876be86bcd093
Try to download image 57a2e180cbb8b3daf21a51681232e88d145ebd8955a62ada48f876be86bcd093 from remote images...
>>> Creating container node1... - 🏭             
>>> [node1] - [started] 💣                
   🏡  - echo "Run container command ${my_var}"
Run container command value1
>>> [node1] - apk add curl - ☕ 
(1/4) Installing ca-certificates (20191127-r4)
(2/4) Installing nghttp2-libs (1.41.0-r0)
(3/4) Installing libcurl (7.69.1-r3)
(4/4) Installing curl (7.69.1-r3)

The container is been created and all hooks are been executed.

$> lxc list
|           NAME           |  STATE  |         IPV4         |                     IPV6                      |         TYPE          | SNAPSHOTS |
| node1                    | RUNNING | (eth0) | fd42:380a:f674:76f3:216:3eff:fef0:52f8 (eth0) | CONTAINER (EPHEMERAL) | 0         |

Congratulations! Your first project has been deployed!