Installing and using LXC Containers on CentOS 7

LXC allows us to share Linux kernel to run application in something similar to chroot environment. Lets take a look at how to install and manage LXC on CentOS 7. Containers reside in /var/lib/lxc/ directory


yum install epel-release
yum install debootstrap perl libvirt
yum install lxc lxc-templates
systemctl start lxc.service
systemctl start libvirtd
systemctl status lxc.service

Check status


Create LXC Containers

To list templates

ls -alh /usr/share/lxc/templates/

To list existing containers

yum install lxc-extra

To create for example cirros LXC Container

lxc-create -n cirrostest -t cirros

To start it in background

lxc-start -n cirrostest -d

Now list active LXC Containers and you should see Container we just started

lxc-ls --active

To connect to console

 lxc-console -n cirrostest

To quit you need to enter Ctrl+a q
In order to stop running Container

lxc-stop -n cirrostest

To delete Container

lxc-destroy -n cirrostest

Container can also be cloned

lxc-clone cirrostest cirrostest-clone