Getting started

Requirements

  • Python 3.4+
  • LXD 2.0+
  • getfacl/setfacl if you plan to use shared folders
  • any provisioning tool you wish to use with LXD-Nomad

Building nomad on Linux

LXD-Nomad should build very easily on Linux provided you have LXD available on your system.

Prerequisite: install LXD

You may want to skip this section if you already have a working installation of LXD on your system.

For Debian and Ubuntu, the following command will ensure that LXD is installed:

$ sudo apt-get install lxd

Note

If you’re using an old version of Ubuntu you should first add the LXD’s apt repository and install the lxd package as follows:

$ sudo add-apt-repository -y ppa:ubuntu-lxc/lxd-stable
$ sudo apt-get update
$ sudo apt-get install lxd

You should now be able to configure your LXD installation using:

$ newgrp lxd  # ensure your current user can use LXD
$ sudo lxd init

Note

The lxd init command will ask you to choose the settings to apply to your LXD installation in an interactive way (storage backend, network configuration, etc). But if you just want to go fast you can try the following commands:

$ newgrp lxd
$ sudo lxd init --auto
$ lxc network create lxdbr0 ipv6.address=none ipv4.address=10.0.3.1/24 ipv4.nat=true
$ lxc network attach-profile lxdbr0 default eth0

You can now check if your LXD installation is working using:

$ lxc launch ubuntu: first-machine && lxc exec first-machine bash

Note

You can use lxc stop first-machine to stop the previously created container.

Install LXD-Nomad

You should now be able to install LXD-Nomad using:

$ pip3 install git+git://github.com/lxd-nomad/lxd-nomad.git

Note

Don’t have pip3 installed on your system? Try this:

$ sudo apt-get install curl
$ curl https://bootstrap.pypa.io/get-pip.py | sudo python3

Command line completion

LXD-Nomad can provide completion for commands and container names.

Bash

If you use Bash, you have to make sure that bash completion is installed (which should be the case for most Linux installations). In order to get completion for LXD-Nomad, you should place the contrib/completion/bash/nomad file at /etc/bash.completion.d/nomad (or at any other place where your distribution keeps completion files):

$ sudo cp contrib/completion/bash/nomad /etc/bash.completion.d/nomad

Make sure to restart your shell before trying to use LXD-Nomad’s bash completion.

ZSH

Coming soon!

Your first Nomad file

Create a file called .nomad.yml (or nomad.yml) in your project directory and paste the following:

name: myproject

containers:
  - name: test01
    image: ubuntu/xenial

  - name: test02
    image: archlinux

This Nomad file defines a project (myproject) and two containers, test01 and test02. These containers will be constructed using respectively the ubuntu/xenial and the archlinux images (which will be pulled from an image server - https://images.linuxcontainers.org by default).

Now from your project directory, start up your containers using the following command:

$ nomad up
Bringing container "test01" up
Bringing container "test02" up
==> test01: Unable to find container "test01" for directory "[PATH_TO_YOUR_PROJECT]"
==> test01: Creating new container "myproject-test01-11943450" from image ubuntu/xenial
==> test01: Starting container "test01"...
==> test01: No IP yet, waiting 10 seconds...
==> test01: Container "test01" is up! IP: [CONTAINER_IP]
==> test01: Doing bare bone setup on the machine...
==> test01: Adding ssh-rsa [SSH_KEY] to machine's authorized keys
==> test01: Provisioning container "test01"...
==> test02: Unable to find container "test02" for directory "[PATH_TO_YOUR_PROJECT]"
==> test02: Creating new container "myproject-test02-11943450" from image archlinux
==> test02: Starting container "test02"...
==> test02: No IP yet, waiting 10 seconds...
==> test02: Container "test02" is up! IP: [CONTAINER_IP]
==> test02: Doing bare bone setup on the machine...
==> test02: Adding ssh-rsa [SSH_KEY] to machine's authorized keys
==> test02: Provisioning container "test02"...

Congrats! You’re in!