Your submission was sent successfully! Close

You have successfully unsubscribed! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates about Ubuntu and upcoming events where you can meet our team.Close

LXD in 4 Easy Steps


on 29 August 2019

Tags: LXD

This article is more than 4 years old.

I needed to install a clean instance of Bionic to test some code, but I did not want to use a full virtual machine as I was in a hurry.  To do this, I used LXD to quickly deploy new Bionic and Xenial instances in minutes. 

If you are not familiar with LXD, it is a next generation container management system that is more like a VM than a traditional container. If you find yourself in a similar spot, here are the 3 commands to get an instance of Linux running and fourth to get you logged in. 


snap install lxd

lxd init

(accept the default/yes to everything)

lxc launch ubuntu:18.04 bionic

lxc exec bionic -- /bin/bash

For the more inquisitive reader, first you install LXD as a snap.

snap install lxd

Then you set up LXD using lxd init and select ‘yes’ to the defaults. 

lxd init

Next, install your system using lxc launch <the image> <nickname> . Below we install Ubuntu 18.04 and give it the nickname ‘bionic’. 

lxc launch ubuntu:18.04 bionic

To connect to the system, use lxc exec. 

lxc exec bionic -- /bin/bash

Now verify your guest OS. 

I specifically wanted to compare something on Xenial and Bionic, so I ran the same commands except I substituted 16.04 for 18.04. 

Create another LXD image of Xenial and execute bash to connect. 

That is your first step in to a larger world. 

What’s Next ? 

One task I do fairly often as a security engineer is set up a web service and attac^H^H to test it for vulnerabilities. With the LXD instances you have created so far they are only available on the host they are running on.  I usually test from a remote host – to do that with LXD you configure a LXD proxy. In the following example, we’ll set up a proxy to allow web traffic into our LXD container. 

lxc exec bionic bash

apt install lighttpd

You are going to want to make sure you are connecting to the right VM, create a page unique to your instance by editing /var/www/html/index.html 

On the host, not the container, you will run lxc config to add a proxy. 

lxc config device add bionic web proxy listen=tcp: connect=tcp:

Now in your container, start your lighttpd service. 

lxc exec bionic bash`

service lighttpd start

Browse from your workstation to the IP of your lxd host. 

With that you know have a very lightweight virtual container environment capable of performing any number of tasks. 

Note For Ubuntu Server Users

These examples were all performed on an Ubuntu 19.04 Desktop, on Ubuntu Server LXD setup is even simpler. For those on Ubuntu 16.04 and 18.04 LXD is often pre-installed as a deb, if you want to switch to the snap run “snap install lxd” followed by “lxd.migrate”. On Ubuntu Server 18.10 and newer LXD is installed as a snap, simply run “lxd init” to begin using LXD.

Ubuntu cloud

Ubuntu offers all the training, software infrastructure, tools, services and support you need for your public and private clouds.

Newsletter signup

Get the latest Ubuntu news and updates in your inbox.

By submitting this form, I confirm that I have read and agree to Canonical's Privacy Policy.

Related posts

Implementing an Android™ based cloud game streaming service with Anbox Cloud

Since the outset, Anbox Cloud was developed with a variety of use cases for running Android at scale. Cloud gaming, more specifically for casual games as...

LXD 5.21.0 LTS is now available

5.21.0 LTS, the stable release of LXD, the system container and VM manager, is now available.

ESXi Alternative: try open source LXD 

LXD is a modern, secure and robust ESXi alternative. With its intuitive CLI and web interface, users can easily get started and deploy and manage their...