Skip to main content

Setting up Linux Containers

Make sure system has 3.10+ {*Specifically, 3.16-0.generic*} for our software purpose.
Install LXC On Ubuntu
1. sudo apt-get update

LXC is available on Ubuntu default repositories. So, Run the following command to install it on Ubuntu, and its derivatives.
2. sudo apt-get install lxc lxctl lxc-templates
The above command will install LXC, and everything needed by LXC.

Now, enter the following command to check everything OK.
3. sudo lxc-checkconfig

Sample Output:
Kernel configuration not found at /proc/config.gz; searching...
Kernel configuration found at /boot/config-3.19.0-15-generic
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled
Multiple /dev/pts instances: enabled
--- Control groups ---
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled
--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled
Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig
Creating Linux Containers (Virtual Units)
LXC is usage very simple, and easy. By default, LXC has many ready made templates. To list all available templates, enter the following command:
sudo ls /usr/share/lxc/templates/

Sample output:
lxc-alpine    lxc-archlinux  lxc-centos  lxc-debian    lxc-fedora  lxc-openmandriva  lxc-oracle  lxc-sshd    lxc-ubuntu-cloud
lxc-altlinux  lxc-busybox    lxc-cirros  lxc-download  lxc-gentoo  lxc-opensuse      lxc-plamo     lxc-ubuntu

To create a new Container, the command should be as below.
sudo lxc-create -n <container-name> -t <template>
Example:  sudo lxc-create -n lxc_01 -t ubuntu

The above command will create a ubuntu container with name “ubuntu01″.
Sample output:
Checking cache download in /var/cache/lxc/vivid/rootfs-amd64 ... 
Installing packages in template: ssh,vim,language-pack-en
Downloading ubuntu vivid minimal ...
I: Retrieving Release 
I: Retrieving Release.gpg 
I: Checking Release signature
I: Valid Release signature (key id 790BC7277767219C42C86F933B4FE6ACC0B21F32)
I: Retrieving Packages 
.
.
.
Generation complete.
Creating SSH2 RSA key; this may take some time ...
2048 ef:14:b4:98:fd:7a:3d:0c:cc:bd:69:17:87:03:a9:7c /etc/ssh/ssh_host_rsa_key.pub (RSA)
Creating SSH2 DSA key; this may take some time ...
1024 b1:ab:2a:4b:c4:77:2e:3f:da:ab:df:24:74:9f:69:a9 /etc/ssh/ssh_host_dsa_key.pub (DSA)
Creating SSH2 ECDSA key; this may take some time ...
256 1a:6a:93:88:05:c5:1c:10:ad:d5:f7:5a:aa:fb:04:57 /etc/ssh/ssh_host_ecdsa_key.pub (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 80:a8:d4:8e:3e:d2:06:a3:96:6d:51:4a:6a:a2:23:47 /etc/ssh/ssh_host_ed25519_key.pub (ED25519)
invoke-rc.d: policy-rc.d denied execution of start.
Current default time zone: 'Asia/Kolkata'
Local time is now:      Fri Jun 12 15:03:30 IST 2015.
Universal Time is now:  Fri Jun 12 09:33:30 UTC 2015.
##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##

Starting Containers
After creating the containers, start it using the following command.
sudo lxc-start -n lxc_01 -d
-d is used to skip all logs getting printed on standard output console.

Now, log in to the container with command:
sudo lxc-console -n lxc_01
Enter the username and password of the container.  The default username and password will be generated while creating new containers. In my case, the default username is ubuntu, and password is ubuntu.

Viewing the list of created containers
To view the list of newly generated containers, enter the following command from your original computer.
sudo lxc-ls   or sudo lxc-ls --fancy

h2. Viewing the complete details of a Container
sudo lxc-info -n lxc_01

Stopping Containers
sudo lxc-stop -n lxc_01

Cloning Containers
It’s possible to clone a new container from an existing container. For example, to clone a new container called “ubuntu02″ from an existing container “ubuntu01″, use the following commands:
sudo lxc-stop -n lxc_01
sudo lxc-clone lxc_01 lxc_02

Sample output:
Created container lxc_02 as copy of lxc-01

Take snapshot of a container
It’s also possible to take snapshot of a container. To take snapshot of the container ubuntu01, enter the following commands:
sudo lxc-stop -n lxc_01
sudo lxc-snapshot -n lxc_01

Sample Output:
lxc_container: lxccontainer.c: lxcapi_snapshot: 2953 Snapshot of directory-backed container requested.
lxc_container: lxccontainer.c: lxcapi_snapshot: 2954 Making a copy-clone.  If you do want snapshots, then
lxc_container: lxccontainer.c: lxcapi_snapshot: 2955 please create an aufs or overlayfs clone first, snapshot that
lxc_container: lxccontainer.c: lxcapi_snapshot: 2956 and keep the original container pristine.

In Ubuntu 15.04, the snapshots will be stored in /var/lib/lxc/ directory of your original host computer.
sudo ls /var/lib/lxc/

In Ubuntu 14.04 and older versions, the snapshots will be stored in /var/lib/lxcsnaps/ directory.
sudo ls /var/lib/lxcsnaps/

Restoring Snapshots
To restore a container from the snapshot, use the following command.
sudo lxc-snapshot -n  lxc_01 -r snap0

Deleting Containers
To destroy a container completely from you original host, enter the following command:
sudo lxc-destroy -n lxc_01

Managing Containers using LXC web console
To install LXC web panel, run the following command:
wget http://lxc-webpanel.github.io/tools/install.sh -O - | sudo bash

Sample output:
--2015-06-12 15:37:41--  http://lxc-webpanel.github.io/tools/install.sh
Resolving lxc-webpanel.github.io (lxc-webpanel.github.io)... 103.245.222.133
Connecting to lxc-webpanel.github.io (lxc-webpanel.github.io)|103.245.222.133|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2678 (2.6K) [application/octet-stream]
Saving to: ‘STDOUT’
-                                           0%[                                                                                        ]       0  --.-KB/s              _     __   _______  __          __  _       _____                 _ 
| |    \ \ / / ____| \ \        / / | |     |  __ \               | |
| |     \ V / |       \ \  /\  / /__| |__   | |__) |_ _ _ __   ___| |
| |      > <| |        \ \/  \/ / _ \ '_ \  |  ___/ _` | '_ \ / _ \ |
| |____ / . \ |____     \  /\  /  __/ |_) | | |  | (_| | | | |  __/ |
|______/_/ \_\_____|     \/  \/ \___|_.__/  |_|   \__,_|_| |_|\___|_|
Automatic installer
-                                         100%[=======================================================================================>]   2.62K  --.-KB/s   in 0.003s 
.
.
.
.
Cleaning up...
Cloning LXC Web Panel...
Cloning into '/srv/lwp'...
remote: Counting objects: 167, done.
remote: Total 167 (delta 0), reused 0 (delta 0), pack-reused 167
Receiving objects: 100% (167/167), 148.85 KiB | 132.00 KiB/s, done.
Resolving deltas: 100% (63/63), done.
Checking connectivity... done.
Installation complete!
Adding /etc/init.d/lwp...
Done
Starting server...done.
Connect you on http://your-ip-address:5000/

Then, access the LXC web panel using URL: http://ip-address:5000. The default username/password is admin/admin.

Issues: UDP Checksum error while running dhcp on WAN links inside a container

Fix: Assuming we follow bridged architecture in bringing up containers,
Make sure to disable "tx-checksum-ip-generic " option on every bridge device attached to container.
Example: ethtool -K br-wan0 tx-checksum-ip-generic off

Comments

Popular posts from this blog

What Why How SDN..???????

What is SDN?   If you follow any number of news feeds or vendor accounts on Twitter, you've no doubt noticed the term "software-defined networking" or SDN popping up more and more lately. Depending on whom you believe, SDN is either the most important industry revolution since Ethernet or merely the latest marketing buzzword (the truth, of course, probably falls somewhere in between). Few people from either camp, however, take the time to explain what SDN actually means. This is chiefly because the term is so new and different parties have been stretching it to encompass varying definitions which serve their own agendas. The phrase "software-defined networking" only became popular over roughly the past eighteen months or so. So what the hell is it? Before we can appreciate the concept of SDN, we must first examine how current networks function. Each of the many processes of a router or switch can be assigned to one of three conceptual planes of operatio...

NETWORKING BASICS

This article is referred from windowsnetworking.com In this article series, I will start with the absolute basics, and work toward building a functional network. In this article I will begin by discussing some of the various networking components and what they do. If you would like to read the other parts in this article series please go to: Networking Basics: Part 2 - Routers Networking Basics: Part 3 - DNS Servers Networking Basics: Part 4 - Workstations and Servers Networking Basics: Part 5 - Domain Controllers Networking Basics: Part 6 - Windows Domain Networking Basics: Part 7 - Introduction to FSMO Roles Networking Basics: Part 8 - FSMO Roles continued Networking Basics: Part 9 – Active Directory Information Networking Basics: Part 10 - Distinguished Names Networking Basics, Part 11: The Active Directory Users and Computers Console Networking Basics: Part 12 - User Account Management Networking Basics: Part 13 - Creating ...

How to install and setup Docker on RHEL 7/CentOS 7

H ow do I install and setup Docker container on an RHEL 7 (Red Hat Enterprise Linux) server? How can I setup Docker on a CentOS 7? How to install and use Docker CE on a CentOS Linux 7 server? Docker is free and open-source software. It automates the deployment of any application as a lightweight, portable, self-sufficient container that will run virtually anywhere. Typically you develop software on your laptop/desktop. You can build a container with your app, and it can test run on your computer. It will scale in cloud, VM, VPS, bare-metal and more. There are two versions of docker. The first one bundled with RHEL/CentOS 7 distro and can be installed with the yum. The second version distributed by the Docker project called docker-ce (community free version) and can be installed by the official Docker project repo. The third version distributed by the Docker project called docker-ee (Enterprise paid version) and can be installed by the official Docker project repo.  This page shows...