LXC学习 分类: 软件插件学习 2015-02-05 14:45 176人阅读 评论(0) 收藏

今天听到同事聊起docker,后来百度了下,说是底层会使用LXC。于是找照猫画虎试验了下

环境:Ubuntu 14.04.1    64

1,安装

sudo apt-get install lxc

报错:

Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
lxc : Depends: apparmor but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

这里按提示下载apparmor,说已经是最新版本

没有好的办法,于是:

sudo apt-get remove apparmor 
sudo apt-get install apparmor
sudo apt-get install lxc

#感觉这样有点危险,担心删除什么重要的东西,还是得找个稳妥的方法


2,检测

lxc-version  #检查版本

lxc-checkconfig  #判断内核是否支持LXC

这里有个小问题,有这么一项:Cgroup memory controller: missing

不过略过不提,一般的missing还是可以使用的LXC的


3,创建客户机

sudo lxc-create -n lxc-busybox -t busybox

lxc-busybox是创建的容器的名字;

busybox是LXC提供的一种简单的常用模板,看百科貌似也可以自己定义配置文件


4,启动

$ sudo lxc-start -n  lxc-busybox

[sudo] password for cloud: 
udhcpc (v1.21.1) started
Sending discover...
Sending select for 10.0.3.26...
Lease of 10.0.3.26 obtained, lease time 3600


Please press Enter to activate this console. 

#这里Enter就可以进去了,有点简陋


BusyBox v1.21.1 (Ubuntu 1:1.21.0-1ubuntu1) built-in shell (ash)
Enter 'help' for a list of built-in commands.


/ # ^[[22;5Rls
ls
bin      etc      lib      mnt      root     selinux  usr
dev      home     lib64    proc     sbin     tmp      var

5,关闭
sudo lxc-stop -n lxc-busybox

#这里另开一个命令行界面执行。在容器内部退出的方法暂时没找到

查看百科还有destory销毁之类的命令,暂未实验


查看资料:

http://tieba.baidu.com/p/2248880856

http://baike.baidu.com/link?url=aVty_Fd8zvP01ykqC1RrlrlVh659_RyNZcFxAXQg39bMv6e30P3imWOFB3W3bRK8dFwWuKurGUVdycKc6ToVWa

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2015-02-05 14:45  冰菓折木  阅读(207)  评论(0编辑  收藏  举报