LXC (Linux Containers) installation and use

Source: Internet
Author: User

The following steps are performed on Ubuntu 12.04.

installation

To use LXC on Ubuntu, install the LXC User Space tool as shown below.

sudo Install LXC

After the installation is complete, run the LXC-CHECKCONIFG tool to check the current Linux kernel support LXC. If everything is enabled, the kernel's support for LXC is ready.

$ lxc-checkconfig

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

Once the LXC container is created, the interface of the window is automatically connected to the bridge, so that the container can connect with the outside world.

How to useCreate LXC

Take the example of creating an Ubuntu 12.04 container named precise.

A basic configuration file needs to be created. Because the configuration file (which can be deleted) is no longer needed after the creation of the LXC, there is no special requirement for the file name and path. This is named Precise.conf, which is placed under the current path:

Lxc.network.type == = = Lxcbr0

Lxcbr0 is a virtual bridge created by the LXC package, ifconfig can know its IP address 10.0.3.1, the network segment 10.0.3.1/24, the container will communicate with the outside world through LXCBR0.

So, you can start creating the container:

sudo lxc-create-n precise-f precise.conf-t Ubuntu---R precise
    • -n Specifies the container name, here is precise.
    • -f Specifies the underlying configuration file, which is the precise.conf created in the previous step.
    • -t specifies the template name, which must be Ubuntu (create Ubuntu 12.04). Each template name, corresponding to a script, is stored in the/usr/lib/lxc/templates directory (the file name is shaped like the lxc-< template name >).
    • -subsequent parameters are passed to the template script;
    • - R is an Ubuntu template script parameter that represents Ubuntu release version code , this must be precise (it is the 12.04 release code).

The creation process can be lengthy. By reading/usr/lib/lxc/templates/lxc-ubuntu, it is not difficult to find that creating Ubuntu containers relies primarily on deboostrap to complete.

Start Lxc

If you need to start lxc immediately, then:

sudo lxc-start-n precise [command]

If you want to run in daemon mode, then:

sudo lxc-start-n precise–d [command]

To start automatically with the Host OS boot:

sudo LN -s/var/lib/lxc/precise/config/etc/lxc/auto/precise.conf

Open the LXC console

Open the console when no IP is set for the container

sudo lxc-console-n precise

You will see the text login screen. You can exit the container console by pressing the hotkey ctrl-a and Q.

More often, login via ssh will be more convenient, especially the key authentication method.

Stop LXC

In most cases, you can close a container by executing poweroff or shutdown-h now within the Guest OS (container). However, there are times when you need to forcibly close a container on the host OS, such as:

sudo lxc-stop-n precise
Delete Lxc

After the container is created, the configuration and data are stored in the/var/lib/lxc/precise directory. Perform

sudo lxc-destroy-n precise

The same as the manual removal of the directory effect.

Transferred from: http://www.malike.net.cn/blog/2013/11/10/lxc-tutorial/

LXC (Linux Containers) installation and use

Related Article

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.