Introduction Linux Container

LXC (Linux Containers) is an operating system–level virtualization method for running multiple isolated Linux systems (containers) on a single control host.

The LXC commonly known as “operating system-level virtualization” or “OS Virtual Environments” containers differ from hypervisor level virtualization. The main difference is that the container model eliminates the hypervisor layer, redundant OS kernels, binaries, and libraries needed to typically run workloads in a VM.

Installing LXC in Fedora 24

Install Required Packages:

  • Package Name and Usage
  • LXC : Main Linux Container
  • debootstrap: Is necessary in order to build Debian-based containers
  • libvirt: will provide basic networking management, such us bridge, NAT and DHCP.
  • lxc-templates : Template scripts to create container of ubuntu, oracle Linux etc…

List of templates:

Installing:

#dnf install lxc lxc-templates lxc-extra debootstrap libvirt

Start “libvirtd” service:

#systemctl list-unit-files | grep libvirtd

Configure network bridge:
Edit the file /etc/lxc/default.conf and change the parameter ‘lxc.network.link’ from ‘lxcbr0’ to ‘virbr0’:

[root@gcpadman-laptop ~]# cat /etc/lxc/default.conf
lxc.network.type = veth
lxc.network.link = virbr0 (By default it will be 
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:xx:xx:xx

Creating container

lxc-create -n container_name -t container_template <Release can be specifed>

lxc-create -n guru -t ubuntu

Note: It will download all the required packages and container will be ready in few minutes …go and get some coffee for yourself :)

Container Administration

  • Listing all container 
    lxc-ls -f
  • Stopping Container 
    lxc-stop -n <container name>
  • Connecting to container console
    lxc-console -n <Container Name>

Note: Use “Ctrl + a” followed by “q” to exit console

  • Query information about a container
    lxc-info -n <Container Name>
  • Stopping Container 
    lxc-stop
  • Cloning Container
    lxc-copy -n <Source Container Name> -N <Clone Name>
  • Destroy a Linux Container 
    lxc-destroy -n <Container Name> -s <Destroy including snapshots> -f <Force>

We have learnt basics of Linux Container, but as a administrator we should understand about container networking, container resource management and configuration files related to container

  1. How networking works in Container?

In our above example I have updated /etc/lxc/default.conf and updated bridge as below;

Let us analyze the bridge virbr0:

Let us analyze this further ….

Container configuration is in the directory respective to that container …

Here we have defined network type as veth. Here are the list of network type supported by LXC:

  • lo — loopback interfaces (more on this later)
  • eth0 — default network interface created by Vagrant
  • eth1 — private network interface which Vagrant created as instructed by our Vagrantfile configuration :private_network
  • eth2 — public network interface which Vagrant created as instructed by our Vagrantfile configuration :public_network
  • lxcbr0 — network bridge which was created automatically when the lxc tools have been installed

Packets are forwarded via iptables;

Like what you read? Give Guruprasad a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.