5

Is there a way how to run LXD inside Docker? eg.

On the host with ubuntu 16.04:

docker run --rm -it --net host --privileged ubuntu bash

In the container:

apt update && apt install -y lxd iproute2 btrfs-tools screen bash-completion curl wget apt-transport-https lxcfs lxd-tools lxd-client vim overlayroot libkmod2 libkmod-dev cgroup-tools cgroupfs-mount cgroup-bin

screen -S lxd
# in screen
lxd --debug --group lxd


lxd init
lxc list
lxc launch ubuntu:16.04 test

LXD daemon works but I can't start LXD container due to errors with cgroups.

error: Error calling 'lxd forkstart test /var/lib/lxd/containers /var/log/lxd/test/lxc.conf': err='exit status 1'
  lxc 20170502151757.409 ERROR lxc_apparmor - lsm/apparmor.c:apparmor_process_label_set:220 - If you really want to start this container, set
  lxc 20170502151757.409 ERROR lxc_apparmor - lsm/apparmor.c:apparmor_process_label_set:221 - lxc.aa_allow_incomplete = 1
  lxc 20170502151757.409 ERROR lxc_apparmor - lsm/apparmor.c:apparmor_process_label_set:222 - in your container configuration file
  lxc 20170502151757.409 ERROR lxc_sync - sync.c:__sync_wait:57 - An error occurred in another process (expected sequence number 5)
  lxc 20170502151757.409 ERROR lxc_start - start.c:__lxc_start:1346 - Failed to spawn container "test".
  lxc 20170502151757.954 ERROR lxc_conf - conf.c:run_buffer:405 - Script exited with status 1.
  lxc 20170502151757.954 ERROR lxc_start - start.c:lxc_fini:546 - Failed to run lxc.hook.post-stop for container "test".

I also tried:

--cap-add=ALL
--volume /dev:/dev
--pid=host
--volume /sys/fs/cgroup:/sys/fs/cgroup
Karel Fiala
  • 51
  • 1
  • 2
  • Admittedly - I have no clue, so I'm writing a comment. I'm just wondering, how come you even use Docker if you are using LXD? You should probably reverse the logic and run Docker inside LXC. – Mjh May 02 '17 at 15:33
  • Yes, I can run Docker inside LXD or LXC without a problem. It's a common task. But imagine, you have a cluster of a few nodes with lightweight OS and Docker. It's easy to run your application or distributed filesystem (eg. GlusterFS) via Docker, even you can run KVM virtual machine as Docker container. Everything will work with Docker Swarm. So the question is: Is there a way how to run LXD inside Docker? Maybe it's not useful but IMHO it should works. – Karel Fiala May 03 '17 at 06:27
  • This seems backwards. LXD is a full Linux environment, Docker is hugely constrained. I would expect the question "can I run Docker inside of LXD" but not "can I run LXD inside of Docker". Asking this question makes me ask, what are you trying to do? and Why?. – JamieB Jul 07 '17 at 14:04

1 Answers1

5

It is possible to run lxc inside docker, so it should also be possible to run lxd. The error indicates that you need to add the line

lxc.aa_allow_incomplete = 1

to your container config.

I did a proof of concept that shows how an lxc container can easily be run within a docker container: https://github.com/micw/docker-lxc-demo

Michael Wyraz
  • 3,638
  • 1
  • 27
  • 25