LXC/LXD as an alternative to Virtualbox for local development

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.

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:

1 Like

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

1 Like

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:

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 I’ve whipped up which should get them into a similar fun space.

1 Like

Wow. Now that is pretty hardcore.

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

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?

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:

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:

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:

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 which is a replacement for Vagrant built around LXD. It works pretty well as it is, but it’s still in heavy development.

1 Like

@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.

1 Like

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

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 ?

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 theansible_connection=local in the host file which caused Ansible to work on the host and not the container …

1 Like

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

For those who are using Debian, LXD is not yet in the repos : LXD Debian wiki

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/

1 Like

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!

Do you have ssl enabled in group_vars/development/wordpress_sites.yml ?

Have you tried setting it to false?

I will try to reproduce your set-up.

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