有没有办法在 Docker 中运行 LXD?

Kar*_*ala 6 docker lxd

有没有办法在 Docker 中运行 LXD?例如。

在 ubuntu 16.04 的主机上:

docker run --rm -it --net host --privileged ubuntu bash
Run Code Online (Sandbox Code Playgroud)

在容器中:

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
Run Code Online (Sandbox Code Playgroud)

LXD 守护进程可以工作,但由于 cgroup 错误,我无法启动 LXD 容器。

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".
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

--cap-add=ALL
--volume /dev:/dev
--pid=host
--volume /sys/fs/cgroup:/sys/fs/cgroup
Run Code Online (Sandbox Code Playgroud)

Mic*_*raz 6

可以在 docker 内运行 lxc,因此也应该可以运行 lxd。该错误表明您需要添加以下行

lxc.aa_allow_incomplete = 1
Run Code Online (Sandbox Code Playgroud)

到您的容器配置。

我做了一个概念证明,展示了如何在 docker 容器中轻松运行 lxc 容器: https: //github.com/micw/docker-lxc-demo