Getting Started with lxc container

LXC is a userspace interface for the Linux kernel containment features. Through a powerful API and simple tools, it lets Linux users easily create and manage system or application containers.

This Technical document contains configuration used for deployment of lxc container.

Todo

  • Install lxc.
  • Install lxc-templates (Unfortunately the templates are not installed by default with sudo apt-get install lxc)
  • Download images for container.
  • Running Images

Install lxc container

I using ubuntu to host containner so for quick Install lxc container using apt.

alex@Alex-Laptop:~$ apt-get install -y lxc

Download images for container

after we install lxc now we must download images.

alex@Alex-Laptop:~$ sudo lxc-create -t download -n [images-name] -- --dist ubuntu --release trusty --arch amd64

for thats command Iam download distro ubuntu with realese trusty and 64bit

if process done you can see your image with sudo lxc-ls --fancy

NAME           STATE   AUTOSTART GROUPS IPV4 IPV6
[images-name] STOPPED 0         -      -    -   

Running Images

for starting images you can use this command.

alex@Alex-Laptop:~$ sudo lxc-start --name [images-name] --daemon

this will be start with daemon mode you can see the images now running with ip 10.0.3.164

NAME           STATE   AUTOSTART GROUPS IPV4       IPV6
[images-name] RUNNING 0         -      10.0.3.164 -   

if you want AUTOSTART when container down you can change configuration like below.

alex@Alex-Laptop:~$ sudo vi /var/lib/lxc/orbit-logstash/config
...
lxc.start.auto = 1
...
alex@Alex-Laptop:~$ sudo lxc-ls --fancy
NAME           STATE   AUTOSTART GROUPS IPV4       IPV6
[images-name] RUNNING 1         -      10.0.3.164 -

append lxc.start.auto = 1 to config and you can change ip address in that config files.

if you want to know info thats image you can use this.

alex@Alex-Laptop:~$ sudo lxc-info --name [images-name]
Name:           [images-name]
State:          RUNNING
PID:            29141
IP:             10.0.3.164
CPU use:        1.18 seconds
BlkIO use:      304.00 KiB
Memory use:     5.96 MiB
KMem use:       0 bytes
Link:           vethE92PEP
 TX bytes:      3.82 KiB
 RX bytes:      3.40 KiB
 Total bytes:   7.22 KiB

and if you want login to image can be use this.

alex@Alex-Laptop:~$ sudo lxc-attach --name [images-name]

ok thas it…if you want to now more you can going to official document lxc container

^RAR

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.