How to create and manage LXC containers on Ubuntu ?, Create lxc containers in ubuntu

Source: Internet
Author: User

How to create and manage LXC containers on Ubuntu ?, Create lxc containers in ubuntu
Install LXC on Ubuntu

$ Sudo apt-get install lxc

After installation, run lxc-checkconifg to check whether the Linux kernel supports LXC. If everything is enabled, the kernel is ready to support LXC.

$ Lxc-checkconfig

After installing the LXC tool, you will find that the default bridge interface (lxcbr0) of LXC has been automatically created (configured in/etc/lxc/default. conf ).

$ Ifconfig lxcbr0

After the LXC container is created, the window interface is automatically connected to the bridge, so that the container can be connected to the outside world.
Create LXC container
Find the available lxc template in the/usr/share/LXC/templates directory.
$ ls /usr/share/lxc/templates

1.Create a configration file, named lxc_common.conf:
lxc.network.type = vethlxc.network.flags = uplxc.network.name = eth0lxc.network.link = lxcbr0

2.Change mirrors:
sudo vim /usr/share/lxc/templates/ubuntu

Change this to the faster mirror server you know:
MIRROR=http://archive.ubuntu.com/ubuntuSECURITY_MIRROR=http://security.ubuntu.com/ubuntu

3. The LXC template is actually a script used to create a container for a specific Linux environment. You need to use this template when creating an LXC container.

For example, to create an Ubuntu container, run the following command:
$ sudo lxc-create -n precise -f lxc_common.conf -t ubuntu -- -r precise

4.Configure the network, sudo vim /etc/default/lxc-net, change the configs if you like, I have uncomment this line:
LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf

5.Use a fixed ip address for “precise” container, sudo vim /etc/lxc/dnsmasq.conf:
Dhcp-host = precise, 10.0.3.2

Manage LXC containers
Now that we know how to create and start the LXC container, let's take a look at how we can handle the running container.
First, we want to access the container console. To do this, type the following command:
$ sudo lxc-console -n precise
Restart lxc-net:
$ sudo service lxc-net restart

Start the lxc container:
$ sudo lxc-start -n precise
Stop the lxc container:
$ Sudo lxc-stop-n precise

For details, see LXC installation and configuration.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.