Setting up basic lxc application or OS container in Cent-OS 6.3

From Notes_Wiki

Home > CentOS > CentOS 6.x > Virtualization tools > Lxc > Setting up basic lxc application or OS container in Cent-OS 6.3

To create an application (/bin/bash or /usr/sbin/sshd) or OS container using lxc in Cent-OS use following steps:

  1. Download latest lxc userspace tools from http://lxc.sourceforge.net/download/lxc/
  2. Run 'lxc-checkconfig' and ensure that everything appears as enabled.
  3. Setup bride networking.
    1. Add line 'BRIDGE=br0' to 'ifcfg-eth0'. Then copy 'ifcfg-eth0' to 'ifcfg-br0'.
    2. In 'ifcfg-br0' one should have following lines
      DEVICE="br0"
      TYPE=Bridge
      BOOTPROTO=dhcp
      NM_CONTROLLED="no"
      ONBOOT="yes"
    3. Do 'service network restart'
    4. Test network connectivity by pinging. Ensure by 'brctl show' that eth0 is connected to br0.
  4. Download openvz container images from http://wiki.openvz.org/Download/template/precreated
  5. Use 'virt-manager' GUI and connect to LXC hypervisor. Try to create application container for '/bin/bash' to verify basic working of lxc.
  6. Create a folder for lxc containers such as '/mnt/data1/lxc'
  7. Create a folder for first container such as '/mnt/data1/lxc/centos1'
  8. Extract downloaded openvz container into centos1 folder
  9. Chroot to container folder and do the following
    1. Edit file '/etc/rc.d/rc.sysinit' of the container and comment line that starts udev
    2. Go to '/etc/sysconfig/network-script/' and delete 'ifcfg-venet' etc. files. Create proper 'ifcfg-eth0' files with following values
      DEVICE=eth0
      BOOTPROTO=static
      IPADDR=10.3.3.150
      NETMASK=255.255.255.0
      GATEWAY=10.3.3.1
      DNS1=10.4.3.222
      ONBOOT="yes"
  10. Use 'passwd' to set root password.
  11. Edit '/etc/ssh/sshd_config' and set 'UsePAM=no' to disable use of PAM
  12. Also use 'chkconfig httpd on' to enable starting of apache on start-up. This is not required but helps in testing TCP connections to container in rare case, that SSH is not working.
  13. Use 'virt-manager' GUI and create a container. Boot it and ping it. Try to ping and open web server of created container.
  14. Try to ssh to container as root using password set earlier.


Home > CentOS > CentOS 6.x > Virtualization tools > Lxc > Setting up basic lxc application or OS container in Cent-OS 6.3