Linux Container 学习

09 Aug 2015

Linux Container学习:LXC安装试用,对容器虚拟化有一个感性认识。

安装LXC

安装环境

windows 7使用 VirtualBox 启动 Ubuntu。Ubuntu安装LXC。

安装LXC

sudo apt-get install lxc

创建容器

创建container

sudo lxc-create -n container1
lxc-create: symbol lookup error: /usr/lib/i386-linux-gnu/liblxc.so.1: undefined symbol: cgmanager_get_pid_cgroup_abs_sync

undefined sysbol错误,可能是Lib版本不匹配,update后解决

sudo apt-get upgrade

创建sshd container

以模板 sshd 创建名为 sshd 的容器

sudo lxc-start -n sshd -t sshd

container shell

sudo lxc-attach -n sshd
bash-4.3# pwd
/
bash-4.3# ls
bin  dev  dhclient.conf  etc  home  lib  lib64  proc  root  run  run-dhcp  sbin  sys  tmp  usr  var

inside容器

bash-4.3# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
udp        0      0 0.0.0.0:68              0.0.0.0:*                          
udp        0      0 0.0.0.0:18566           0.0.0.0:*                          
udp6       0      0 :::53494                :::*                               
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ]         DGRAM                    26430    
bash-4.3# ps -elf
F S UID        PID  PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
4 S root         1     0  0  80   0 -   971 wait   03:00 ?        00:00:00 /usr/sbin/init.lxc -- /usr/sbin/sshd
1 S root        36     1  0  80   0 -  1414 poll_s 03:00 ?        00:00:00 dhclient eth0 -cf /dhclient.conf
5 S root        40     1  0  80   0 -  1948 poll_s 03:00 ?        00:00:00 /usr/sbin/sshd
4 S root       102     0  0  80   0 -  1759 wait   04:21 ?        00:00:00 /bin/bash
0 R root       106   102  0  80   0 -  1662 -      04:23 ?        00:00:00 ps -elf

遗留问题