Update 17 June 2019: https://blog.simos.info/how-to-run-lxd-containers-in-wsl2/
WSL2 is the new subsystem on Windows to run the Ubuntu runtime.
Compared to WSL1, WSL2 actually uses the Linux kernel running inside a lightweight version of Hyper-V.
Therefore, it should be possible to get LXD running in there.
I just tried getting LXD to work on WSL2 and here are the results.
The short story is that I could not make it work.
The Ubuntu image for WSL1 and WSL2 does not support
systemdyet, therefore you cannot get the snap package of LXD to install. There is some ongoing work and workarounds at https://github.com/Microsoft/WSL/issues/994 (see towards the end), however I could not make them work.
The Ubuntu image for WSL1 and WSL2 does come with LXD pre-installed (apt package). As a service it is not running by default, therefore, you need to start it. Remember those commands?
sudo service lxd start
You then need to run
sudo lxd initto initialize LXD.
3.1. By default, LXD is happy to use
brtfs, and manages to initialize it. All good regarding the storage driver.
3.2. LXD fails to create
lxdbr0with the following error. If you retry without networking, then
sudo lxd initcompletes successfully.
Error: Failed to create network 'lxdbr0': Failed to run: iptables -w -t filter -I INPUT -i lxdbr0 -p udp --dport 67 -j ACCEPT -m comment --comment generated for LXD network lxdbr0: iptables: No chain/target/match by that name.
When you try to launch a container, you get the following error (was trying to get
macvlanto work at the same time, hence the networking error):
lxc mycontainer 20190614081018.500 ERROR utils - utils.c:safe_mount:1179 - Operation not permitted - Failed to mount "sysfs" onto "/usr/lib/x86_64-linux-gnu/lxc/sys" lxc mycontainer 20190614081018.500 ERROR conf - conf.c:lxc_mount_auto_mounts:724 - Operation not permitted - Failed to mount "sysfs" on "/usr/lib/x86_64-linux-gnu/lxc/sys" with flags 0 lxc mycontainer 20190614081018.500 ERROR conf - conf.c:lxc_setup:3539 - Failed to setup first automatic mounts lxc mycontainer 20190614081018.500 ERROR start - start.c:do_start:1263 - Failed to setup container "mycontainer" lxc mycontainer 20190614081018.500 ERROR sync - sync.c:__sync_wait:62 - An error occurred in another process (expected sequence number 5) lxc mycontainer 20190614081018.500 WARN network - network.c:lxc_delete_network_priv:2589 - Operation not permitted - Failed to remove interface "eth0" with index 7 lxc mycontainer 20190614081018.500 ERROR lxccontainer - lxccontainer.c:wait_on_daemonized_start:842 - Received container state "ABORTING" instead of "RUNNING" lxc mycontainer 20190614081018.501 ERROR start - start.c:__lxc_start:1939 - Failed to spawn container "mycontainer" lxc 20190614081018.506 WARN commands - commands.c:lxc_cmd_rsp_recv:132 - Connection reset by peer - Failed to receive response for command "get_state"