复制代码代码如下:lxc-execute -n test /bin/bash 这个会启动一个lxc并给出类似的一个cmd窗口,网络是与操作系统共用的,这里好像仅仅是创建了一个命名空间 如果没有指定-f,默认的隔离将被使用,这个命令当你需要一个快速在一个隔离的环境中运行程序。在物理机上和container中都会运行lxc-init,在宿主机上面,这个程序用于转发lxc-kill 信号到已经启动的程序中 ,在container中,这个程序的pid为1,它会fork出要执行的命令(pid为2)并执行。
lxc-start 用于在容器中执行给定命令 用法:lxc-start -n name [-f config_file] [-c console_file] [-d] [-s KEY=VAL] [command] -d 将容器当做守护进程执行 -f 后面跟配置文件 -c 指定一个文件作为容器console的输出,如果不指定,将输出到终端 -s 指定配置 如果没有指定命令,lxc-start 将要运行 /sbin/init 例如: 复制代码代码如下:lxc-start -n foo -f foo.conf -d /bin/bash 注:1.如果容器还不存在,lxc-start会自动创建一个,容器停止运行后会被自动销毁 2.lxc-start配置优先级与lxc-execute相同 3.lxc-start 与lxc.execute的异同: lxc-start 和 lxc-execute都可以在容器中启动进程,区别在于lxc-start直接创建进程,lxc-execute先创建lxc-init进程,然后在lxc-init中fork一个进程来执行。(关于第4点,lxc-init所占的是一个什么样的地位?) The orphan process group and daemon are not supported by this command, use the lxc-execute command instead If no command is specified, lxc-start will use the default "/sbin/init" command to run a system container. 4.lxc-start用于在容器启动system,lxc-execute用于在容器执行应用程序
lxc-kill 发送信号给容器中的第一个用户进程(容器内部进程号为2的进程) 用法:lxc-kil -n name SIGNUM -n 后面跟容器名 SIGNUM 信号 (此参数可选,默认SIGKILL) 例如: 复制代码代码如下:lxc-kill -n foo
lxc-stop 用于停止容器中所有的进程 用法:lxc-stop -n name -n后面跟要停止的容器名 例如: 复制代码代码如下:lxc-stop --n foo
lxc-destroy 用于销毁容器 用法:lxc-destroy -n name -n后面跟要停止的容器名 例如: 复制代码代码如下:lxc-destroy --n foo
lxc-cgroup 用于获取或调整与cgroup相关的参数 用法:lxc-cgroup -n name subsystem value -n 后面跟要调整的容器名 例如: 复制代码代码如下:lxc-cgroup -n foo devices.list lxc-cgroup -n foo cpuset.cpus "0,3"