LXC/LXD as an alternative to Virtualbox for local development

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

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!

3 Likes

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.