为什么 lxc 在 lxc-webpanel 中按预期运行,而不是在 CLI 或 python 中运行?

Why does lxc function as expected with lxc-webpanel and not from either CLI or python?

观察

  1. lxc-webpanel 按预期运行
  2. 从命令行界面发出的lxc命令和returns非零退出状态1
  3. 从 python 解释器中的 lxclite 模块调用的函数引发异常

问题:

如何找到允许 lxc-webpanel 按预期运行的缺失因素?当我在 bash shell 中发出 lxc 命令时,或者当我从 python 解释器调用 lxc-webpanel 执行的相同 defs 时,lxc 命令失败。

目标:

能够使用 bash CLI 或 python 会话来管理 lxc 容器

系统信息:

使用 lxc-webpanel 创建了名为 'test-container' 的容器。

观察一:lxc-webpanel试用截图

观察 2:来自 bash CLI

的 lxc 命令

test-container doesn't exist

attach.c: lxc_attach: 635 failed to get the init pid

观察 3:来自 ipython3

的 lxclite def 调用

ContainerDoesntExists Traceback (most recent call last) in () ----> 1 lxc.info(container)

../../python3_dev/_lxc/lxclite/init.py in info(container) 122 if not exists(container): 123 raise ContainerDoesntExists( --> 124 'Container {} does not exist!'.format(container)) 125 126 output = _run('lxc-info -qn {}|grep -i "State\|PID"'.format(container),

ContainerDoesntExists: Container test-container does not exist!

注意:lxc-checkconfig 输出:

Kernel configuration not found at /proc/config.gz; searching...

Kernel configuration found at /boot/config-3.13.0-48-powerpc64-smp

--- Namespaces ---

Namespaces: [enabled]

Utsname namespace: [enabled]

Ipc namespace: [enabled]

Pid namespace: [enabled]

User namespace: [enabled]

Network namespace: [enabled]

Multiple /dev/pts instances: [enabled]

--- Control groups ---

Cgroup: [enabled]

Cgroup clone_children flag: [enabled]

Cgroup device: [enabled]

Cgroup sched: [enabled]

Cgroup cpu account: [enabled]

Cgroup memory controller: [enabled]

Cgroup cpuset: [enabled]

--- Misc ---

Veth pair device: [enabled]

Macvlan: [enabled]

Vlan: [enabled]

File capabilities: [enabled]

Note : Before booting a new kernel, you can check its configuration

usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig

这条评论 ❝The user id in the lxc instance should equal the user id in the host.❞ 让我找到了解决方案。

当我以 root 身份 运行 一个 IPython 会话时,一切都按预期运行。呸!

ps -aux | grep python

root 1327 0.0 0.4 18956 13188 ? S 09:55 0:00 /usr/bin/python /srv/lwp/lwp.py

sudo lxc-info --name test-container

Name: test-container

State: STOPPED