LXC Docker

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24
At a glance
Powered by AI
The key takeaways are that LXC is a lightweight operating system-level virtualization technology that relies on namespaces and cgroups to provide isolation between containers. Docker is a tool that provides a higher level of abstraction on top of LXC to package and run applications in containers in a portable way across different Linux distributions.

LXC is an operating system-level virtualization that provides lightweight virtualization using containers. It relies on cgroups, SELinux, and namespaces to isolate containers, and is included in the Linux kernel. It provides near-native performance and can be managed with tools like libvirt-lxc or lxc-tools.

Common use cases for LXC containers include running lightweight web servers, creating testing environments, isolating applications from each other for security and reliability, and running low latency applications.

INTRODUCTION TO

LINUX CONTAINTER (LXC)


AND DOCKER
Michael Lessard. RHCA
Senior Solutions Architect, Red Hat
michaellessard
January 2014

LXC DOCKER | MICHAEL LESSARD

A bit of history Virtualization and containers

Chroot (version 7 Unix, 1979)

FreeBSD Jails (FreeBSD 4, 2000)

Linux vserver (Linux, Oct 2001)

Para-virtualization Xen (Linux, 2003)

Solaris zones (Solaris 10, 2004)

OpenVZ (Linux, 2005)

Full virtualization KVM (Linux, 2007)

Linux Containers - LXC (Linux 2.6.29 2009)


In red Virtualization on the os level (containers)

LXC DOCKER | MICHAEL LESSARD

What is LXC ?

An operating system-level virtualization

Light weight virtualization

Containers

Relies on cgroup,selinux and namespace

Included in the kernel

Can be managed using libvirt-lxc (RHEL and Fedora)


or lxc-tools (Fedora)
Perceived near bear metal performance

LXC DOCKER | MICHAEL LESSARD

LXC DOCKER | MICHAEL LESSARD

Uses cases

Lightweight web servers

Testing environment

Application isolation

Low latency app

LXC DOCKER | MICHAEL LESSARD

Weaknesses

Locked into running the host kernel

Unlike a fully virtualized machine, you are restricted to


the kernel running on the host

No Windows support

LXC DOCKER | MICHAEL LESSARD

Demo

LXC DOCKER | MICHAEL LESSARD

DEMO WITH LIBVIRT LXC (FEDORA)


# yum install lxc libvirt-daemon-driver-lxc
# sytemctl restart libvirtd
Demo lxc container1 and container2
Demo virt-sandbox
Demo Docker

LXC DOCKER | MICHAEL LESSARD

DEMO USING VIRT-MANAGER

LXC DOCKER | MICHAEL LESSARD

10

LXC DOCKER | MICHAEL LESSARD

11

LXC DOCKER | MICHAEL LESSARD

12

LXC DOCKER | MICHAEL LESSARD

13

LXC DOCKER | MICHAEL LESSARD

14

LXC DOCKER | MICHAEL LESSARD

15

LXC DOCKER | MICHAEL LESSARD

LXC DEMO USING THE COMMAND LINE


# virsh uri
qemu:/// session
# export VIRSH_DEFAULT_CONNECT_URI=lxc:///
# virsh uri
lxc:///

16

LXC DOCKER | MICHAEL LESSARD

VALIDATE LXC CAPABILITIES


# virsh capabilities

17

LXC DOCKER | MICHAEL LESSARD

CONFIGURE A CONTAINER
# vi lxc_example.xml

<domain type='lxc'>
<name>lxc_example</name>
<memory>500000</memory>
<os>
<type>exe</type>
<init>/bin/sh</init>
</os>
<vcpu>1</vcpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<interface type='network'>
<source network='default'/>
</interface>
<console type='pty' />
</devices>
</domain>

18

LXC DOCKER | MICHAEL LESSARD

DEFINE AND START THE CONTAINER


# virsh define lxc_example.xml
# virsh start lxc_example
# virsh list
# virsh dominfo lxc_example
# virsh console lxc_example

19

LXC DOCKER | MICHAEL LESSARD

DEMO WITH VIRTSANDBOX - HTTPD


# yum install libvirt-sandbox httpd
# systemctl restart libvirtd
# virt-sandbox-service create -C --network dhcp -u httpd.service httpd
# systemctl start httpd_sandbox
# virt-sandbox-service connect httpd
# dhclient eth0
# ifconfig
Point browser on http://(ip-address)
note : /var/lib/libvirt/filesystems

20

LXC DOCKER | MICHAEL LESSARD

NEXT STEP

21

LXC DOCKER | MICHAEL LESSARD

DOCKER

Container-based tooling

High level tool for LXC

Portable deployment across machines

Public shared containers

Automatic build

Tool ecosystem (nova,


salt, chef, puppet,
jenkins, openshift ...)
And more ...
http://docker.io

22

LXC DOCKER | MICHAEL LESSARD

DOCKER DEMO (Fedora 20)


# yum install docker-io
# sytemctl start docker ; systemctl enable docker
# docker search ubuntu
# docker pull ubuntu
# sudo docker run ubuntu apt-cache search memcached
# docker search arch
# docker pull base/arch
# docker run base/arch pacman -Ss memcached
# docker images
# docker run -i -t ubuntu /bin/bash
# docker ps -a
# docker rmi base/arch
23

LXC DOCKER | MICHAEL LESSARD

You might also like