有没有一种方法可以在Docker内运行LXD?

6
有没有一种方法可以在Docker中运行LXD? 例如。
在安装有Ubuntu 16.04的主机上:
docker run --rm -it --net host --privileged ubuntu bash

在容器中:
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守护程序可以工作,但由于cgroups出现错误,我无法启动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".

我也尝试了以下方法:

--cap-add=ALL
--volume /dev:/dev
--pid=host
--volume /sys/fs/cgroup:/sys/fs/cgroup

诚然 - 我一点都不清楚,所以我写了一个注释。我只是好奇,如果你正在使用LXD,为什么还要使用Docker呢?你应该反过来, 在LXC中运行Docker。 - Mjh
是的,我可以在LXD或LXC中轻松运行Docker。这是一项常见任务。但想象一下,您有一个由几个节点组成的集群,其使用轻量级操作系统和Docker。通过Docker,轻松运行您的应用程序或分布式文件系统(例如GlusterFS),甚至可以将KVM虚拟机作为Docker容器运行。一切都可以在Docker Swarm中工作。所以问题是:有没有办法在Docker内部运行LXD?也许这没什么用处,但在我看来应该是可以的。 - Karel Fiala
这似乎是颠倒的。LXD 是一个完整的 Linux 环境,而 Docker 受到极大的限制。我会期望问题是“我能在 LXD 中运行 Docker 吗?”,而不是“我能在 Docker 中运行 LXD 吗?”问这个问题让我想问,你想做什么?为什么要这样做? - JamieB
1个回答

6

在Docker内部运行LXC是可能的,因此运行LXD也应该是可能的。错误提示表明您需要添加以下行:

lxc.aa_allow_incomplete = 1

将其添加到您的容器配置中。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接