Ubuntu 16.04 LTS users can install LXD with:
apt-get install lxd
Ubuntu 14.04 LTS users can also install LXD using backports:
apt-get -t trusty-backports install lxd
Alternatively, to get the latest upstream release, a PPA is available:
add-apt-repository ppa:ubuntu-lxc/lxd-stable apt-get update apt-get dist-upgrade apt-get install lxd
The package creates a new "lxd" group which contains all users allowed to talk to
lxd over the local unix socket. All members of the "admin" and "sudoers" groups are automatically added.
If your user isn't a member of one of these groups, you'll need to manually add your user to the "lxd" group.
Because group membership is only applied at login, you then either need to close
and re-open your user session or use the "newgrp lxd" command in the shell you're going to interact with lxd from.
Then to do the initial configuration of the LXD daemon, including, if you want to, setting up optimized storage (ZFS),
making the deamon visible on the network and configuring networking for the containers:
sudo lxd init
LXD is available for Ubuntu Core as a Snap package in the store.
You can install it with:
sudo snap install lxd
After that, LXD can be interacted with through the "lxd.lxc" command.
It should be noted that the server certificate generation can take a long time if you're working on a device like
the rpi2 so it might be a few minutes before LXD will respond to the lxc command.
There are currently packages for multiple distributions including Gentoo and, of course, Ubuntu.
Users of other distributions might find it in their package manager too.
If it is not there yet please download and build LXD from git or use our latest release tarball.
Instructions for both are available here.
LXD is image based. Containers must be created from an image and so the image store
must get some images before you can do much with LXD.
There are three ways to feed that image store:
lxc image import <file> --alias <name>
Using a remote image server is as simple as adding it as a remote and just using it:
lxc remote add images 126.96.36.199 lxc launch images:image-name your-container
An image list can be obtained with:
lxc image list images:
LXD comes with 3 default remotes providing images:
To start a container from them, simply do:
lxc launch ubuntu:14.04 my-ubuntu lxc launch ubuntu-daily:16.04 my-ubuntu-dev lxc launch images:centos/6/amd64 my-centos
If you already have a lxd-compatible image file, you can import it with:
lxc image import \<file\> --alias my-alias
And then start a container using:
lxc launch my-alias my-container
See the image specification for more details.
Assuming that you imported an Ubuntu cloud image using the "ubuntu" alias, you can create your first container with:
lxc launch ubuntu first
That will create and start a new ubuntu container as can be confirmed with:
Your container here is called "first". You also could let LXD give it a random name by
just calling "lxc launch ubuntu" without a name.
Now that your container is running, you can get a shell inside it with:
lxc exec first -- /bin/bash
Or just run a command directly:
lxc exec first -- apt-get update
To pull a file from the container, use:
lxc file pull first/etc/hosts .
To push one, use:
lxc file push hosts first/tmp/
To stop the container, simply do:
lxc stop first
And to remove it entirely:
lxc delete first
The "lxc" command line tool can talk to multiple LXD servers.
It defaults to talking to the local one using a local UNIX socket.
Remote operations require the following two commands having been run on the remote server:
lxc config set core.https_address "[::]" lxc config set core.trust_password some-password
The first tells LXD to bind all addresses on port 8443.
The latter sets a trust password to be used when contacting that server.
Now to talk to that remote LXD, you can simply add it with:
lxc remote add host-a <ip address or DNS>
This will prompt you to confirm the remote server fingerprint and then ask you for the password.
And after that, use all the same command as above but prefixing the container
and images name with the remote host like:
lxc exec host-a:first -- apt-get update