# LXC/LXD as an alternative to Virtualbox for local development

**URL:** https://discourse.roots.io/t/lxc-lxd-as-an-alternative-to-virtualbox-for-local-development/5149
**Category:** trellis
**Created:** 2015-10-28T14:47:17Z
**Posts:** 63

## Post 1 by @treb0r — 2015-10-28T14:47:18Z

Over the last few days I’ve been experimenting with [LXD](http://www.ubuntu.com/cloud/tools/lxd) as an alternative to Virtualbox for local WordPress development tasks.

The advantages are huge:

1. Speed

LXC/LXD runs at bare metal speeds. Your container will run as fast as your host machine. New containers take around 1 second (!) to launch.

1. Ease of use

The LXD command line tools are intuitive and useful

1. Efficient Use of resources

LXC/LXD is much lighter than Virtualbox .

To get started, follow the instructions [here](https://insights.ubuntu.com/2015/03/20/installing-lxd-and-the-command-line-tool/) to install LXC/LXD on your local machine (sorry OSX users, this stuff is Linux only).

Once you are up and running you will need to import a base image:

```
lxd-images import ubuntu --alias ubuntu
```

Once the image is imported, you can launch your first container

```
lxc launch ubuntu firstcontainer
```

Once the container is launched, you may stop it like

```
lxc stop firstcontainer
```

…and start it again:

```
lxc start firstcontainer
```

To mount a shared host directory, stop the container and first make the directory world writeable on the host (I’m sure there is probably a more graceful way of doing this!)

```
sudo chmod -R go+w /path/to/shared/directory/on/host
```

Then issue this command on the host:

```
lxc config device add firstcontainer webroot disk path=/srv/www/example.com/current source=/home/user/sites/example.com/site
```

Start the container, and make sure that your .env file is indeed readable from the container:

```
lxc exec firstcontainer -- /bin/bash
cd /srv/www/example.com/current
cat .env
```

Now have a look at the output from:

```
lxc list
```

(on the host) and you will see the ip address of your new container. Add the development domain (example.dev) to your /etc/hosts file and make sure it is pointing at the correct ip.

Once your dev domain is set up you need to access the container again and add your ssh key to the root user’s ./ssh/authorized\_keys file in the container. Once that’s done, you can use ansible to provision the container as normal. Just use the development hosts file and group vars as you would for staging or production.

```
ansible-playbook -i hosts/development server.yml
```

I find I need to run the script at least twice to get it to work. For some reason swapon always fails first time but is fine second time.

All being well, you should now be able to work on your local dev site using LXC/LXD instead of Virtualbox.

I’m going to figure out how to do all this with Vagrant, stay tuned, and any help gratefully received.

---

## Post 2 by @swalkinshaw — 2015-10-28T14:59:00Z

This is pretty cool, thanks! Would you be interested in expanding on this for a blog post on [roots.io](http://roots.io)? If you don’t want to put it somewhere else that is.

I’ll talk to @benlobovits to see if that’s something we could do (“guest” writers).

---

## Post 3 by @treb0r — 2015-10-28T15:00:31Z

@swalkinshaw that would be a huge honour!

---

## Post 4 by @swalkinshaw — 2015-10-28T16:20:07Z

Okay we can do this pretty easily. Want to formalize your post a little and post it to a Gist or something? (as Markdown). No rush or anything and I’ll give it an edit after as well.

---

## Post 5 by @treb0r — 2015-10-28T16:31:15Z

Yes, I can do that.

Do you think I should do that now or wait until I’ve got vagrant working with LXC/LXD?

Maybe a blog post based on this discourse post can be part one and then I’ll write a follow up when I’ve got it all working with vagrant?

---

## Post 6 by @swalkinshaw — 2015-10-28T16:46:32Z

Yeah two parts sounds good.

---

## Post 7 by @kalenjohnson — 2015-10-29T00:38:51Z

I didn’t know Vagrant could work with LXC. That sounds amazing.

And since I use Ubuntu for my desktop, count me in as very curious and excited to have bare-metal speed :joy:

---

## Post 8 by @treb0r — 2015-10-29T10:56:23Z

> [@kalenjohnson](#):
>
> And since I use Ubuntu for my desktop, count me in as very curious and excited to have bare-metal speed

I’ve got two containers set up and running Roots based projects. LXC/LXD almost seem too good to be true: fast, stable and extremely lightweight. I just noticed that if you shutdown the host machine without stopping the containers first, LXC automatically brings them back up again on boot. Cool :smile:

---

## Post 9 by @mikeschinkel — 2015-12-25T08:44:05Z

Am I correct in assuming that to bypass VirtualBox you have to be using Ubuntu on your development machine, vs. Mac OS X or Windows?

---

## Post 10 by @swalkinshaw — 2015-12-26T05:10:47Z

Correct. Check out the full blog post here: [https://roots.io/linux-containers-lxd-as-an-alternative-to-virtualbox-for-wordpress-development/](https://roots.io/linux-containers-lxd-as-an-alternative-to-virtualbox-for-wordpress-development/)

---

## Post 11 by @mikeschinkel — 2015-12-26T05:22:38Z

Thanks.

FWIW I actually came to the forum to ask after reading the full post. If it was explicitly stated then I missed it, sorry.

---

## Post 12 by @bmullan — 2015-12-26T14:21:21Z

Note that Docker no longer uses LXC. In 2014 Docker started using their own libcontainer instead of LXC.  
reference: [https://github.com/docker/libcontainer](https://github.com/docker/libcontainer)

---

## Post 13 by @treb0r — 2015-12-29T16:18:44Z

> [@mikeschinkel](#):
>
> Am I correct in assuming that to bypass VirtualBox you have to be using Ubuntu on your development machine, vs. Mac OS X or Windows?

Not just Ubuntu, any modern Linux should do the trick. Ubuntu is the reference platform though as Canonical are driving development of LXD.

---

## Post 14 by @rdab — 2016-01-27T16:36:07Z

Nice post!  
I’d like to know if you are using something to automate and easily reproduce containers, something like Vagrant maybe.

---

## Post 15 by @treb0r — 2016-01-29T11:05:22Z

I’m working on it. Been away for a few weeks but back now and will have something to show soon, hopefully.

In the meantime, I find it’s pretty simple to use LXC/LXD without Vagrant.

Once you have the shared folders configured and SSH working pretty much everything else is handled by the trellis ansible scripts.

I’ve become used to using this setup now and Virtualbox just seems so sluggish in comparison.

---

## Post 16 by @anokpe — 2016-02-23T09:51:16Z

I am using linux mint, just started testing lxd. I have installed lxd as instructed by this post.  
But while trying to add official repository for images i get following message.

# lxc remote add images [images.linuxcontainers.org](http://images.linuxcontainers.org)

No command ‘lxc’ found, did you mean:  
Command ‘axc’ from package ‘afnix’ (universe)  
Command ‘llc’ from package ‘llvm’ (universe)  
Command ‘lpc’ from package ‘lprng’ (universe)  
Command ‘lpc’ from package ‘lpr’ (universe)  
Command ‘lpc’ from package ‘cups-bsd’ (main)  
Command ‘lc’ from package ‘mono-devel’ (main)

Is there something I should be doing with lxc? To my knowledge lxc is already installed on my machine along with lxd.

Hope to get help, Thank you.

---

## Post 17 by @treb0r — 2016-02-23T10:28:22Z

Check lxc is installed:

`which lxc`

If not you should install it.

---

## Post 18 by @anokpe — 2016-02-23T10:36:44Z

thanks for the reply, i checked it earlier and they are installed.

apt-get install lxc  
Reading package lists… Done  
Building dependency tree  
Reading state information… Done  
lxc is already the newest version.  
0 upgraded, 0 newly installed, 0 to remove and 374 not upgraded.

apt-cache policy lxc  
lxc:  
Installed: 2.0.0~rc1-0ubuntu1~ubuntu14.04.1~ppa1  
Candidate: 2.0.0~rc1-0ubuntu1~ubuntu14.04.1~ppa1  
Version table:  
\*\*\* 2.0.0~rc1-0ubuntu1~ubuntu14.04.1~ppa1 0  
500 [http://ppa.launchpad.net/ubuntu-lxc/lxd-stable/ubuntu/](http://ppa.launchpad.net/ubuntu-lxc/lxd-stable/ubuntu/) trusty/main amd64 Packages  
100 /var/lib/dpkg/status  
1.0.8-0ubuntu0.3 0  
500 [http://archive.ubuntu.com/ubuntu/](http://archive.ubuntu.com/ubuntu/) trusty-updates/main amd64 Packages  
1.0.7-0ubuntu0.7 0  
500 [http://security.ubuntu.com/ubuntu/](http://security.ubuntu.com/ubuntu/) trusty-security/main amd64 Packages  
1.0.3-0ubuntu3 0  
500 [http://archive.ubuntu.com/ubuntu/](http://archive.ubuntu.com/ubuntu/) trusty/main amd64 Packages

---

## Post 19 by @treb0r — 2016-02-23T10:38:40Z

What happens if you try running lxc as root?

---

## Post 20 by @anokpe — 2016-02-23T10:40:34Z

It give same message as above.

lxc  
No command ‘lxc’ found, did you mean:  
Command ‘axc’ from package ‘afnix’ (universe)  
Command ‘llc’ from package ‘llvm’ (universe)  
Command ‘lpc’ from package ‘lprng’ (universe)  
Command ‘lpc’ from package ‘lpr’ (universe)  
Command ‘lpc’ from package ‘cups-bsd’ (main)  
Command ‘lc’ from package ‘mono-devel’ (main)

---

## Post 21 by @treb0r — 2016-02-23T10:46:06Z

Strange.

Seems like a problem with paths.

Do you have apparmor installed?

---

## Post 22 by @anokpe — 2016-02-23T11:07:00Z

Yes this is strange, and no i have not installed apparmor. There isn’t any executable command file for lxc under /usr/bin/ either. And what is this!! linux mint site is also down no support nor forum :frowning:

I think i should try ubuntu 15.\* for testing now. This is no good.

---

## Post 23 by @treb0r — 2016-02-23T11:21:37Z

Well for what it’s worth, Ubuntu is the reference platform because Canonical are driving the development of LXD. I’ve had no problems using this stuff at all.

I’m running 14.04 but will upgrade to 16.04 as soon as it’s out.

The officially supported ZFS in 16.04 is going to make LXD fly.

---

## Post 24 by @anokpe — 2016-02-26T09:21:26Z

hello again treb0r , I have Ubuntu 15.04 desktop version now. Unfortunately while trying to add remote images i get following error message.

lxc remote add images [images.linuxcontainers.org](http://images.linuxcontainers.org)

error: remote images exists as [https://images.linuxcontainers.org:8443](https://images.linuxcontainers.org:8443)

What does it signify. I searched web for this issue but could not find proper answer. Could you please help me on that?  
Thank you

---

## Post 25 by @treb0r — 2016-02-26T10:24:41Z

Looks like images is already configured. Try running:

`lxc remote list`

You should see something like:

`+-----------------+-----------------------------------------+--------+ | NAME | URL | PUBLIC | +-----------------+-----------------------------------------+--------+ | images | https://images.linuxcontainers.org:8443 | YES | | local (default) | unix:// | NO | +-----------------+-----------------------------------------+--------+`

In which case you’re good to go.

---

## Post 26 by @anokpe — 2016-02-26T10:32:38Z

Thanks treb0r.  
Yup it is as you said they are already configured.  
But strange thing is I checked it earlier and it was empty. Just before you replied i also added PPA repository which i thought was not necessary on 15.04 and I am pretty sure it was not the case for my error message.

Thank you once again.

---

## Post 27 by @treb0r — 2016-02-26T10:37:32Z

No problem. I personally prefer to stick with LTS releases and I think things will be smoother once 16.04 is out.

Let me know how you get on or if you need a hand with it.

---

## Post 28 by @treb0r — 2016-04-07T08:21:29Z

Just a quick heads up that LXD is now at version 2.0 and there have been some major changes to how networking is configured.

I’ll post details here and I’m planning to do another blog post soon.

---

## Post 29 by @treb0r — 2016-04-08T08:33:34Z

The authoritative guide to LXD networking in version 2.0, hot off the press:

> **[LXD networking: lxdbr0 explained](https://insights.ubuntu.com/2016/04/07/lxd-networking-lxdbr0-explained/)**
>
> Recently, LXD stopped depending on lxc, and thus moved to using its own bridge, called lxdbr0. lxdbr0 behaves significantly differently than lxcbr0: it is ipv6 link local only by default (i.e. there is no ipv4 or ipv6 subnet configured by default),...

I couldn’t get the setup wizard to work so I followed the instructions and edited the config file directly. Now it’s all working fine.

---

## Post 30 by @niccolox — 2016-04-10T18:55:41Z

hi there,

I have a Github issue on LXD "Synced Folders"

> <https://github.com/lxc/lxd/issues/1879>

I am super interested in working through to some kind of working solution on this

for me there are two big LXD issues, networking and synced folders

I know both can be done, but I read many options

perhaps an Ansible role or two would work well for this as it seems out of scope for LXD according to LXD maintainers

---

## Post 31 by @niccolox — 2016-04-10T19:20:57Z

added another question / issue to the LXD networking blog

> <https://github.com/tych0/tycho.ws/issues/1>

---

## Post 32 by @treb0r — 2016-04-11T09:11:23Z

> [@niccolox](#):
>
> I am super interested in working through to some kind of working solution on this
> 
> for me there are two big LXD issues, networking and synced folders

I don’t see an issue with either of these.

Synced folders do require global write permissions on the host system, which is obviously not ideal, but apart from that it all seems to work fine.

LXD networking has been in a state of flux and last week they moved away from LXC networking entirely as described in that blog post.

After having a few problems with the setup process I just edited the config file directly and now it’s all working nicely.

The vision is to get this working properly with Vagrant and then packaged as a proper alternative to Virtualbox for Trellis. This has been difficult because LXD itself has been a moving target recently, particularly the networking stuff.

I’m hoping things will settle down a bit with the release of 16.04.

---

## Post 33 by @bloodearnest — 2016-05-25T10:20:42Z

I got synced folders working with the following script.

> <https://gist.github.com/bloodearnest/ebf044476e70c4baee59c5000a10f4c8>

It sets up subuid/gid map for your uid, and then creates a custom profile for you user that you can use with lxc launch.

Seems to work well for me, and is very flexible.

---

## Post 34 by @treb0r — 2016-05-25T11:51:15Z

That looks way cool.

I’ll give it a go, thanks!

---

## Post 35 by @treb0r — 2016-05-25T11:53:39Z

Do I need to pass anything in to lxc launch to get this to work?

---

## Post 36 by @chipk — 2016-08-14T05:32:54Z

I am new to this community. I am very excited about the roots ecosystem, but while going through the Trellis tutorial, I fell down on the Vagrant / Virtualbox set up. It turns out that my laptop, running Ubuntu Trusty, would not run a Virtualbox VM because its hardware doesn’t support it. Then I stumbled across your post and started learning about LXC/LXD. It works just fine on my laptop.

While researching, I discovered that there is a custom Vagrant provider plug-in for LXC [https://github.com/fgrehm/vagrant-lxc](https://github.com/fgrehm/vagrant-lxc). I haven’t tried it yet, I am still in LXC/LXD learning mode (and I want to get through your tutorial on the manual setup) as well. I don’t know if you have tried this yet. I intend to, after I gain some familiarity with the toolset and configuration. I did want to let you know about this.

---

## Post 37 by @treb0r — 2016-08-14T05:53:18Z

Hey @chipk great to hear you have LXD working!

I have seen the Vagrant provider plugin for LXC but unfortunately it won’t work with LXD (as far as I can tell anyway).

I owe the roots guys another blog post about this stuff, this time about using Vagrant with LXD but have struggled to find enough documentation to get it working properly.

Having said that, I have been making progress and have been in touch with Canonical about a couple of issues. A few tips for getting up and running manually without Vagrant:

That gist from @bloodearnest above will allow you to mount a shared directory without the need to make the target directory world writable.

Also, before provisioning your dev environment, check out this thread:

> [@'sudoer_passwords' is undefined (LXD)](https://discourse.roots.io/t/sudoer-passwords-is-undefined-lxd/6493/3):
>
> @treb0r The sudoer password definitions are used in the users role. Standard Trellis runs dev.yml for development and server.yml for staging/production. Given that dev.yml does not run the users role, [roots/trellis#560](https://github.com/roots/trellis/pull/560) removed the unused sudoer password definitions from group\_vars/development. However, I see that you are probably provisioning your [LXD container](https://roots.io/linux-containers-lxd-as-an-alternative-to-virtualbox-for-wordpress-development/) as development using server.yml. This means the users role will run and need the sudoer password definitions, but will no longer find …

…and make sure to add back those sudoer password definitions.

Let me know if you need a hand.

---

## Post 38 by @chipk — 2016-08-16T18:49:46Z

Wow! The learning curve on LXC/LXD has been circuitous, and required me to get my head around a lot of concepts. I am beginning to see daylight, though. Anyway, I just wanted to let you know I saw your response and thank you for your guidance and offer of assistance. I will update you when I get to the point of having Trellis working, and I definitely will take you up on your offer of help if I get stuck.

---

## Post 39 by @Walter_Martin — 2016-11-07T01:46:06Z

This is some great info. I’m just getting to the point where I am doing enough small WordPress sites for customers that I need a more streamlined solution than what I have been doing, which is creating individual KVM instances for each site based on a few default instances I have already created. VVV sounds great but I hate having to switch to Virtual Box and don’t have time at the moment to figure out if I can make it work with KVM. Have you made any further progress on getting LXD and Vagrant working together?

---

## Post 40 by @treb0r — 2016-11-07T09:21:49Z

> [@Walter_Martin](#):
>
> Have you made any further progress on getting LXD and Vagrant working together?

Unfortunately not.

I’ve found that just working with the LXC/LXD tools in combination with trellis gives great results. I just setup the .dev domains in my local /etc/hosts file and handle everything manually. I like the control that gives and don’t really feel the need for Vagrant anymore.

---

## Post 41 by @kuxi — 2016-11-30T11:07:16Z

I’m trying to make this work over my local network on a spare box with Mint installed. Stuck trying to get an ssh connection through to the VM.

---

## Post 42 by @treb0r — 2016-11-30T11:23:01Z

I’m not familiar with Mint, but assuming it has all of the required Ubuntu LXD software available you probably just need to configure LXD networking.

This article should help:

> **[LXD networking: lxdbr0 explained](https://insights.ubuntu.com/2016/04/07/lxd-networking-lxdbr0-explained/)**
>
> Recently, LXD stopped depending on lxc, and thus moved to using its own bridge, called lxdbr0. lxdbr0 behaves significantly differently than lxcbr0: it is ipv6 link local only by default (i.e. there is no ipv4 or ipv6 subnet configured by default),...

---

## Post 43 by @kuxi — 2016-11-30T11:41:48Z

Thanks Rob. Yes Mint is basically Ubuntu and LXD/LXC is working as expected.

---

## Post 44 by @treb0r — 2016-11-30T11:56:24Z

Hi Sunil,

Let me know how you get on.

Once you have the networking sorted it should work well. Just remember that if you are using an LXD host for development you will need to provision it manually with Trellis which will require you to add back a couple of lines in files removed in this commit:

> <https://github.com/roots/trellis/pull/560>

---

## Post 45 by @Simon_Ryan — 2016-12-02T10:19:23Z

Great post treb0r.

For those OSX (now macOS) using readers you kindly apologised to I’d like to point them to a [mini lxd datacenter](http://timedistort.blogspot.com.au/2016/11/a-mini-lxd-datacenter-for-osx-macos.html) I’ve whipped up which should get them into a similar fun space.

---

## Post 46 by @treb0r — 2016-12-02T11:01:19Z

Wow. Now that is pretty hardcore.

Apparently LXD is going to be available and working in Windows too.

---

## Post 47 by @Simon_Ryan — 2016-12-02T12:00:50Z

Yes a very interesting direction things are going in. I wonder if its possible to do the lxd install using the various hacks out there for getting a full Ubuntu under the windows 10 bash feature?

---

## Post 48 by @treb0r — 2016-12-02T12:09:04Z

Well according to a Canonical developer I have spoken with, Microsoft has committed to ‘fully integrate’ Ubuntu into Windows 10. They already have LXD working in the cloud and he says it’s coming to the desktop soon.

I’m old enough to remember MacOS before OSX, and it really seemed that Apple were creating the perfect OS with OSX by adding a solid UNIX foundation. These days it seems that Apple are doing everything they can to hinder developers and the new macOS seems squarely targeted at consumers.

Meanwhile Microsoft are quietly bringing Linux to the party. What a time to be alive :grinning:.

Interesting article about Microsoft and Ubuntu here:

> **[How Microsoft Plans To "Mix" Ubuntu Linux And Windows 10 In Creators Update](https://fossbytes.com/microsoft-ubuntu-linux-windows-10-creators-update/)**
>
> Microsoft is planning to introduce tons of new features in its Windows 10 Creators Update. The company is looking to add more functionalities in Windows 10 Linux subsystem and Windows console to make things easier for developers.

---

## Post 49 by @Simon_Ryan — 2016-12-05T11:35:45Z

Very interesting. After reading that and feeling somewhat inspired, I spent time tinkering around with windows 10. I managed to get LXD installed under the new _Windows Subsystem for Linux_, It turns out there is no actual linux kernel, but rather a set of api’s that allow native elf binaries to happily run. “lxd init” failed and complained about not being able to open a socket and I kind of doubt they would have implemented the required emulation needed for the kernel control groups and namespaces to work properly. Unfortunately ZFS is not going to work either however, I guess it is early days yet. :slight_smile:

---

## Post 50 by @treb0r — 2016-12-05T18:26:33Z

Well who knows. I don’t have a Windows machine here so I just go on what I read and what people tell me.

This article from last year seems to suggest that it is coming down the line:

> **[Canonical and Microsoft working together on containers | ZDNet](http://www.zdnet.com/article/canonical-and-microsoft-working-together-on-containers/)**
>
> Will every Ubuntu server soon be ready to work with Windows and Azure LXD-based container services?

---

## Post 51 by @hsoft — 2017-02-18T19:43:06Z

Given the nature of this discussion, I though you would be interested in following the development of a tool we’ve been working on, [LXDock](https://github.com/lxdock/lxdock) which is a replacement for Vagrant built around LXD. It works pretty well as it is, but it’s still in heavy development.

---

## Post 52 by @kuxi — 2017-07-11T09:55:57Z

@treb0r I made progress with LXD/LXC and now have a headless box which I can fire up fresh vps’s. Its all very smooth and snapshotting is working great. Just wanted to thank you for the original write up and encouragement along the way. Its an excellent dev environment.

---

## Post 53 by @treb0r — 2017-07-11T10:20:38Z

Good to hear @kuxi, thanks for letting me know!

---

## Post 54 by @loasishospitality — 2018-12-20T09:23:29Z

whoaa provisioning is blasting fast ! Awesome contrib, thank you @treb0r  
I had so far performance issues with Vagrant on Debian and working with LXD seems to be what I am looking for.

I get an error with MariaDB Installation, with the repo “Ubuntu Stretch” … (Debian Strech is my host OS)

```
TASK [mariadb : Add MariaDB PPA] ***********************************************
System info:
  Ansible 2.4.6.0; Linux
  Trellis version (per changelog): "Fix Vagrant trigger path"
---------------------------------------------------
MODULE FAILURE
Traceback (most recent call last):
  File "/tmp/ansible_94bOGY/ansible_module_apt_repository.py", line 556, in
<module>
main()
  File "/tmp/ansible_94bOGY/ansible_module_apt_repository.py", line 544, in
main
cache.update()
  File "/usr/lib/python2.7/dist-packages/apt/cache.py", line 464, in update
raise FetchFailedException(e)
apt.cache.FetchFailedException: E:The repository
'http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.2/ubuntu stretch
Release' does not have a Release file.

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: apt.cache.FetchFailedException: E:The repository 'http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.2/ubuntu stretch Release' does not have a Release file.
fatal: [dev.easternroutes.com]: FAILED! => {"changed": false, "failed": true, "module_stdout": "", "rc": 1}
```

I provisioned a Ubuntu Bionic with : `lxc launch ubuntu:18.04` - Added the webroot path, the virtual host.

The release detection fails, instead of the container distribution name, Ansible gets the host release :

```
TASK [common : Validate Ubuntu version] ****************************************
Trellis is built for Ubuntu 18.04 Bionic as of
https://github.com/roots/trellis/pull/992

Your Ubuntu version is 9.6 stretch
```

Asking the release from the container I get satisfactory result

```
root@er2:~# lsb_release -cs
bionic
```

Any idea what could be wrong here ?

---

## Post 55 by @loasishospitality — 2018-12-20T22:08:15Z

Great everything is working and really really fast compared with Vagrant !

Many thanks @treb0r - you made my week, if not my month : previously 5-10s loading time per page with Vagrant / Virtual Box on Debian. Now loading almost instantly !

The issue was I left the`ansible_connection=local` in the host file which caused Ansible to work on the host and not the container …

---

## Post 56 by @treb0r — 2019-01-10T10:00:25Z

Sorry, only just saw this, glad you got it working!

---

## Post 57 by @loasishospitality — 2019-01-10T11:46:30Z

For those who are using Debian, LXD is not yet in the repos : [LXD Debian wiki](https://wiki.debian.org/LXD)

The turnaround is to install LXD on top of snapd, I followed this tuto to install it : [https://stgraber.org/2017/01/18/lxd-on-debian/](https://stgraber.org/2017/01/18/lxd-on-debian/)

---

## Post 58 by @colinw — 2019-01-10T22:15:12Z

I have been trying to get this (lxd containers) to work running the dev.yml playbook instead of server.yml because I would like to have mailhog running…  
but I am getting a 500 nginx error

I am on Debian, installed lxd via snap… it seems to be working flawlessly.  
I have a username in container with ssh key and hostname set (via container profile)  
changed admin\_user and web\_user and remote\_user to my username in the files:  
trellis/group\_vars/development/main.yml  
trellis/group\_vars/all/users.yml  
trellis/dev.yml  
also user and password in development/vault.yml

ansible ends after running entire playbook with ok=118 changed=85 unreachable=0 failed=0

When checking nginx status in the container, there is an error: “ssl\_stapling” ignored, no OCSP responder URL in the certificate…

Any help would be appreciated!

---

## Post 59 by @treb0r — 2019-01-11T09:06:27Z

Do you have ssl enabled in group\_vars/development/wordpress\_sites.yml ?

Have you tried setting it to false?

---

## Post 60 by @loasishospitality — 2019-01-11T12:09:20Z

I will try to reproduce your set-up.

As for now I am using root login, can you describe this step ?

> [@colinw](#):
>
> I have a username in container with ssh key and hostname set (via container profile)

---

## Post 61 by @colinw — 2019-01-11T18:56:54Z

Sorry… realized it was a permissions issue. After setting the webroot permissions manually to 755 it works!

---

## Post 62 by @colinw — 2019-01-11T19:15:23Z

For anyone else who is attempting this… I have two lxd profiles, one for my user setup and the second for specific dev site settings.

In the user profile I have included:

```
config:
  raw.idmap: |
    uid 1000 1000
    gid 1000 1000
  user.vendor-data: |
    #cloud-config
    users:
      - name: username
        groups: sudo
        shell: /bin/bash
        sudo: ['ALL=(ALL) NOPASSWD:ALL']
    # ensure users shell is installed
        packages:
          - bash
        ssh_authorized_keys:
          - ssh-rsa AA...etc...
description: users w-ssh +bridge
devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: lxdbr0
    type: nic
```

and in the site specific one I have:

```
config:
  user.user-data: |
    #cloud-config
    package_upgrade: true
    hostname: example.test
    mangage_etc_hosts: true
    packages:
      - python-minimal
      - python-software-properties
      - build-essential
      - git
      - python-mysqldb
      - libnss-myhostname
      - dbus
      - python-pycurl
      - curl
    timezone: America/Vancouver
description: example dev profile
devices:
  root:
    path: /
    pool: default
    type: disk
  webroot:
    path: /srv/www/example.test/current
    source: /home/username/Websites/projects/example/site
    type: disk
```

Then launch the container:

`lxc launch -p username -p example ubuntu:16.04 containername`

Then:  
`lxc list for ip`  
add ip.address example.test to /etc/hosts

make sure you can ssh in:  
`ssh username@example.test`

then run ansible playbook:  
`ansible-playbook -i hosts/development dev.yml -e env=development`

Comments / Improvements welcome!

---

## Post 63 by @treb0r — 2019-06-18T09:17:05Z

> [@treb0r](#):
>
> Well according to a Canonical developer I have spoken with, Microsoft has committed to ‘fully integrate’ Ubuntu into Windows 10. They already have LXD working in the cloud and he says it’s coming to the desktop soon.

It took a lot longer than expected, but LXD is now taking baby steps on to Windows 10.

Not ready for prime time, but this is really interesting. - WSL 2 is running a Linux kernel inside a lightweight virtual machine, so the performance gains won’t be as spectacular as LXD on real Linux.

Still, I bet it will be a lot better than Virtualbox. Waiting for things to settle down a bit before I give it a try.

> **[How to run LXD containers in WSL2](https://blog.simos.info/how-to-run-lxd-containers-in-wsl2/)**
>
> Microsoft announced in May that the new version of Windows Subsystem for Linux 2 (WSL 2), will be running on the Linux kernel, itself running alongside the Windows kernel in Windows. In June, the f…
