SlideShare uma empresa Scribd logo
1 de 36
LXC
Doro Wu
fcwu.tw@gmail.com
Who am I
• Software Engineer at Canonical
• Skills
– Legacy, EFI BIOS
– Linux Kernel
– Android framework & HAL & Apps
– Window Apps with wxPython
– Linux Desktop Stack
• Links
– Blog, LinkedIn, github
2
In this talk
3
LXC
Applications Internal
Virtualization
• Hardware Virtualization
– Full: VirtualBox
– Para: Xen, KVM
• Software
– Operating system-level virtualization
• LXC
• OpenVZ
• Linux VServer
• FreeBSD Jails
• chroot
4
Containers
Hardware
OS
P0 Pn
P0 Pn
LXC
• LXC (LinuX Containers)
– Run a Linux system within another Linux system
• Container
– a group of processes on a Linux box, put together
in an isolated environment
• Inside the box, it looks like a VM
• Outside the box, it looks like normal processes
5
Benefit
• Speed - fast
– Boots, create VM, deploy tasks
• Footprint - small
– aufs or overlayfs
• Virtualization
– Own network interface
– Own filesystem
– Isolation and security
– Isolation and resource usage
6
Use Cases
• Continuous Integration
– Run 100 tests in 100 VMs
• Escape dependency hell
• Do whatever you did in VMs
– But faster
7
QUICK START
8
• Ubuntu 12.04.2
9
$ sudo apt-get install lxc
$ sudo lxc-create -t ubuntu -n u1
$ sudo lxc-start -n u1 -d
$ sudo lxc-console -n u1
username/name: ubuntu
^aq
$ sudo lxc-list
$ sudo lxc-info -n u1
$ sudo lxc-shutdown -n u1
$ sudo lxc-destroy -n u1
Cheat Sheet
• lxc-create - create system container
• lxc-destroy - destroy container
• lxc-start - start sys container
• lxc-stop - stop sys container
• lxc-shutdown - safely shut down a container
• lxc-execute - Run command in a app
container
• lxc-start-ephemeral - start an one-time
container
• lxc-ls - shorter output than lxc-list
• lxc-list - List all containers
• lxc-info - Print info on the state of a
container
• lxc-monitor - Monitor state
• lxc-wait - Wait for a state change
• lxc-restore - restore containers from
backups made by lxc-backup
• lxc-backup - back up the root filesystems
• lxc-freeze - freeze a running container
• lxc-unfreeze - unfreeze a frozen container
• lxc-cgroup - View and set container control
group settings
• lxc-netstat - Execute netstat in a running
container
• lxc-ps - View process info in a running
container
10
create x destroy
• lxc-create -n {ctx-name} -t {template name}
– $ sudo lxc-create -n u1 -t ubuntu
– $ sudo lxc-create -n u2 -t ubuntu -- -r raring
– Templates are in /usr/lib/lxc/lxc-*
– When first created, a base filesystem will put in
/var/cache/lxc/
– Then copy a instance to /var/lib/lxc/{name}/
• config
• fstab
• rootfs/
• lxc-destroy -n {name}
11
start x stop x shutdown
• lxc-start -n {name} [-d] [-o logfile] [--logpriority=LEVEL]
– Start a system-level container (/sbin/init)
• lxc-shutdown -n name [-w] [-r] [-t timeout]
– Cleanly shut down a container.
• Send SIGPWR
• If not stopped, call lxc-stop which sends SIGKILL
– -w: wait for shutdown to complete.
– -r: reboot (ignore -w).
– -t timeout: wait at most timeout seconds (implies -w), then
kill the container.
• lxc-stop -n {name}
12
execute x start-ephermal
• lxc-execute -n {NAME} -- {COMMAND}
– Run a command in application-level container
• lxc-start-ephemeral [-d] [-u user] [-S key] -o {orig} --
[COMMAND]
– Runs an ephemeral (one-off) container
– $ sudo lxc-start-ephemeral -u ubuntu -o u1 -- uname -a
– Options:
• orig - name of the original container
• user - the user to connect to the container as
• key - the path to the SSH key to use to connect
• -d - run in the background
13
cgroup
• lxc-cgroup -n {name} {subsystem} {value}
– View and set container control group settings
– $ sudo lxc-cgroup -n u1 memroy.limit_in_bytes
256M
– $ lxc-cgroup -n u1 cpu.shares 512
• maximum is 1024
– $ lxc-cgroup -n u1 cpuset.cpus 0,3
– Configure - /var/lib/lxc/{name}/config, such as
• lxc.cgroup.memory.limit_in_bytes = 256M
14
clone x backup x restore
• sudo lxc-clone -o {orig} -n {new}
• sudo lxc-backup {name} {number}
• sudo lxc-restore {name} {number}
15
APPLICATIONS
16
Docker
Docker can help you easily create lightweight,
portable, self-sufficient containers from any
application
17
Deploy Remote Desktop
18
$ sudo apt-get install linux-image-extra-`uname -r`
$ sudo add-apt-repository ppa:dotcloud/lxc-docker
$ sudo apt-get update
$ sudo apt-get install lxc-docker
$ docker run -i -t ubuntu /bin/bash
$ docker build -t vpsee/docker-desktop git://github.com/rogaha/docker-
desktop.git
$ docker images
$ docker run vpsee/docker-desktop
$ docker port a581df505cb9 22
$ docker ps
$ ssh -XC docker@localhost -p 49153 ./docker-desktop
$ xpra --ssh="ssh -p 49153" attach ssh:docker@localhost:10
http://www.vpsee.com/2013/07/use-docker-and-lxc-to-build-a-desktop/
19
Dockerfile allow you to automate the steps you
would normally manually take to create an image.
Juju
Automate your cloud infrastructure
Configure, manage, maintain, deploy and scale efficiently with
best-practice Charms on any public, private or hybrid cloud from
a powerful GUI or the command-line.
20
Deploy WordPress
21
$ sudo apt-add-repository ppa:juju/stable
$ sudo apt-get update
$ sudo apt-get install lxc mongodb-server juju juju-core
$ juju init
$ sed -i ‘s/default: amazon/default: local/’ ~/.juju/environments.yaml
$ sudo juju bootstrap
$ sudo juju deploy wordpress
$ sudo juju deploy mysql
$ sudo juju add-relation wordpress mysql
$ sudo juju expose wordpress
$ sudo juju status
https://juju.ubuntu.com/docs/
22
$ sudo juju status
environment: local
machines:
"0":
agent-state: started
agent-version: 1.14.1.1
dns-name: 10.0.3.1
instance-id: localhost
series: precise
"2":
agent-state: started
agent-version: 1.14.1.1
dns-name: 172.16.0.5
instance-id: doro-local-machine-2
series: precise
"3":
agent-state: started
agent-version: 1.14.1.1
dns-name: 172.16.0.5
instance-id: doro-local-machine-3
series: precise
services:
mysql:
charm: cs:precise/mysql-27
exposed: false
relations:
cluster:
- mysql
db:
- wordpress
units:
mysql/0:
agent-state: started
agent-version: 1.14.1.1
machine: "2"
public-address: 10.0.3.162
wordpress:
charm: cs:precise/wordpress-18
exposed: false
relations:
db:
- mysql
loadbalancer:
- wordpress
units:
wordpress/0:
agent-state: error
agent-state-info: 'hook failed: "install"'
agent-version: 1.14.1.1
machine: "3"
public-address: 10.0.3.118
23
$ sudo juju destroy-environment
$ sudo apt-get purge juju juju-core mongo-
server
24
Vagrant
Development environments made easy
Create and configure lightweight, reproducible,
and portable development environments.
25
Create Ubuntu 12.04 64-bits
26
$ vagrant box add precise64 http://files.vagrantup.com/precise64.box
$ mkdir my_box
$ cd my_box
$ vagrant init precise64
$ vagrant up
$ vagrant ssh
$ vagrant suspend
$ vagrant halt
$ vagrant destroy
vagrant-lxc, https://github.com/fgrehm/vagrant-lxc
INTERNAL
27
http://www.slideshare.net/dotCloud/scale11x-lxc-talk-16766275
http://lwn.net/Articles/531114/
Get Code
• $ apt-get source lxc
• configure
– /etc/lxc/lxc.conf
– /etc/lxc/auto
• init script
– /etc/default/lxc
– /etc/init/lxc.conf
– /etc/init/lxc-net.conf
– /etc/dnsmasq.d-available/lxc
28
Namespaces
• Partition essential kernel structures to create
virtual environments
• Types
– pid
– net
– ipc
– mnt
– uts (hostname)
– user
29
Create Namespaces
• flags to the system call clone()
– mnt: CLONE_NEWNS
– uts: CLONE_NEWUTS
– ipc: CLONE_NEWIPC
– pid: CLONE_NEWPID
– net: CLONE_NEWNET
– user: CLONE_NEWUSER
• command unshare
– unshare [-m] [-u] [-i] [-n] <program> [args...]
30
Create Namespace in Code
31
Network
• Each container has its own interface, routing table, iptables
rules…
• Communication between containers via pairs of veth
interface
• /etc/init/lxc-net.conf: iptables, dnsmasq…
32
[1] $ sudo unshare --net bash
[2] $ echo $$
[1] $ sudo ip link add name lxcbr0 type veth peer name vethdoro
[1] $ ip link set vethdoro netns <PID>
[2] $ ip link set vethdoro name eth0
[2] $ ifconfig eth0 192.168.1.2
[2] $ ifconfig lo 127.0.0.1
[1] $ ifconfig addif vethdoro
Mount
• Deluxe chroot()  pivot_root()
• Filesystems mounted in a mnt namespace are
visible only in this namespace
• You need to remount special filesystem
– procfs
– devpts
• Commands
– unshare --mount <program>
– mount {--make-[r]shared | --make-[r]slave | -- make --
[r]private | --make-unbindable} <mount-object>
33
http://www.ibm.com/developerworks/linux/library/l-mount-namespaces/index.html
cgroup
• Everything exposed through filesystem
– cgroup on /sys/fs/cgroup type tmpfs (rw,relatime,mode=755)
– cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,relatime,cpuset)
– cgroup on /sys/fs/cgroup/cpu type cgroup (rw,relatime,cpu)
– cgroup on /sys/fs/cgroup/cpuacct type cgroup (rw,relatime,cpuacct)
• Create a cgroup
– mkdir -p /sys/fs/cgroup/cpu/lxc/u1
– Add PID to cgroup: echo $PID > /sys/fs/cgroup/cpu/lxc/u1/tasks
– Limit: echo 512 > /sys/fs/cgroup/cpu/lxc/u1/cpu.shares
34
Limit & Account
• CPU
– cpu.shares
– cpustat.usage
– cpuset.cpus
• Memory
– memory.[soft_]limit_in_bytes
– memory.stat
• Block I/O
– blkio.throttle.{read,write}.{iops,bps}.device
• RTFM: Documentation/cgroup/*
35
回家吃飯
36

Mais conteúdo relacionado

Mais procurados

Docker Architecture (v1.3)
Docker Architecture (v1.3)Docker Architecture (v1.3)
Docker Architecture (v1.3)rajdeep
 
Performance characteristics of traditional v ms vs docker containers (dockerc...
Performance characteristics of traditional v ms vs docker containers (dockerc...Performance characteristics of traditional v ms vs docker containers (dockerc...
Performance characteristics of traditional v ms vs docker containers (dockerc...Boden Russell
 
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxConAnatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxConJérôme Petazzoni
 
Linux Container Brief for IEEE WG P2302
Linux Container Brief for IEEE WG P2302Linux Container Brief for IEEE WG P2302
Linux Container Brief for IEEE WG P2302Boden Russell
 
An Updated Performance Comparison of Virtual Machines and Linux Containers
An Updated Performance Comparison of Virtual Machines and Linux ContainersAn Updated Performance Comparison of Virtual Machines and Linux Containers
An Updated Performance Comparison of Virtual Machines and Linux ContainersKento Aoyama
 
Lxc – next gen virtualization for cloud intro (cloudexpo)
Lxc – next gen virtualization for cloud   intro (cloudexpo)Lxc – next gen virtualization for cloud   intro (cloudexpo)
Lxc – next gen virtualization for cloud intro (cloudexpo)Boden Russell
 
Realizing Linux Containers (LXC)
Realizing Linux Containers (LXC)Realizing Linux Containers (LXC)
Realizing Linux Containers (LXC)Boden Russell
 
Docker - container and lightweight virtualization
Docker - container and lightweight virtualization Docker - container and lightweight virtualization
Docker - container and lightweight virtualization Sim Janghoon
 
Lxc- Linux Containers
Lxc- Linux ContainersLxc- Linux Containers
Lxc- Linux Containerssamof76
 
Linux Containers From Scratch
Linux Containers From ScratchLinux Containers From Scratch
Linux Containers From Scratchjoshuasoundcloud
 
Container Torture: Run any binary, in any container
Container Torture: Run any binary, in any containerContainer Torture: Run any binary, in any container
Container Torture: Run any binary, in any containerDocker, Inc.
 
Evoluation of Linux Container Virtualization
Evoluation of Linux Container VirtualizationEvoluation of Linux Container Virtualization
Evoluation of Linux Container VirtualizationImesh Gunaratne
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to dockerHiroki Endo
 
Docker storage drivers by Jérôme Petazzoni
Docker storage drivers by Jérôme PetazzoniDocker storage drivers by Jérôme Petazzoni
Docker storage drivers by Jérôme PetazzoniDocker, Inc.
 
Lightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFSLightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFSJérôme Petazzoni
 
CoreOS, or How I Learned to Stop Worrying and Love Systemd
CoreOS, or How I Learned to Stop Worrying and Love SystemdCoreOS, or How I Learned to Stop Worrying and Love Systemd
CoreOS, or How I Learned to Stop Worrying and Love SystemdRichard Lister
 
LXC – NextGen Virtualization for Cloud benefit realization (cloudexpo)
LXC – NextGen Virtualization for Cloud benefit realization (cloudexpo)LXC – NextGen Virtualization for Cloud benefit realization (cloudexpo)
LXC – NextGen Virtualization for Cloud benefit realization (cloudexpo)Boden Russell
 
Inside Docker for Fedora20/RHEL7
Inside Docker for Fedora20/RHEL7Inside Docker for Fedora20/RHEL7
Inside Docker for Fedora20/RHEL7Etsuji Nakai
 
Introduction to linux containers
Introduction to linux containersIntroduction to linux containers
Introduction to linux containersGoogle
 
QNAP COSCUP Container Station
QNAP COSCUP Container StationQNAP COSCUP Container Station
QNAP COSCUP Container StationWu Fan-Cheng
 

Mais procurados (20)

Docker Architecture (v1.3)
Docker Architecture (v1.3)Docker Architecture (v1.3)
Docker Architecture (v1.3)
 
Performance characteristics of traditional v ms vs docker containers (dockerc...
Performance characteristics of traditional v ms vs docker containers (dockerc...Performance characteristics of traditional v ms vs docker containers (dockerc...
Performance characteristics of traditional v ms vs docker containers (dockerc...
 
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxConAnatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
 
Linux Container Brief for IEEE WG P2302
Linux Container Brief for IEEE WG P2302Linux Container Brief for IEEE WG P2302
Linux Container Brief for IEEE WG P2302
 
An Updated Performance Comparison of Virtual Machines and Linux Containers
An Updated Performance Comparison of Virtual Machines and Linux ContainersAn Updated Performance Comparison of Virtual Machines and Linux Containers
An Updated Performance Comparison of Virtual Machines and Linux Containers
 
Lxc – next gen virtualization for cloud intro (cloudexpo)
Lxc – next gen virtualization for cloud   intro (cloudexpo)Lxc – next gen virtualization for cloud   intro (cloudexpo)
Lxc – next gen virtualization for cloud intro (cloudexpo)
 
Realizing Linux Containers (LXC)
Realizing Linux Containers (LXC)Realizing Linux Containers (LXC)
Realizing Linux Containers (LXC)
 
Docker - container and lightweight virtualization
Docker - container and lightweight virtualization Docker - container and lightweight virtualization
Docker - container and lightweight virtualization
 
Lxc- Linux Containers
Lxc- Linux ContainersLxc- Linux Containers
Lxc- Linux Containers
 
Linux Containers From Scratch
Linux Containers From ScratchLinux Containers From Scratch
Linux Containers From Scratch
 
Container Torture: Run any binary, in any container
Container Torture: Run any binary, in any containerContainer Torture: Run any binary, in any container
Container Torture: Run any binary, in any container
 
Evoluation of Linux Container Virtualization
Evoluation of Linux Container VirtualizationEvoluation of Linux Container Virtualization
Evoluation of Linux Container Virtualization
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
Docker storage drivers by Jérôme Petazzoni
Docker storage drivers by Jérôme PetazzoniDocker storage drivers by Jérôme Petazzoni
Docker storage drivers by Jérôme Petazzoni
 
Lightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFSLightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFS
 
CoreOS, or How I Learned to Stop Worrying and Love Systemd
CoreOS, or How I Learned to Stop Worrying and Love SystemdCoreOS, or How I Learned to Stop Worrying and Love Systemd
CoreOS, or How I Learned to Stop Worrying and Love Systemd
 
LXC – NextGen Virtualization for Cloud benefit realization (cloudexpo)
LXC – NextGen Virtualization for Cloud benefit realization (cloudexpo)LXC – NextGen Virtualization for Cloud benefit realization (cloudexpo)
LXC – NextGen Virtualization for Cloud benefit realization (cloudexpo)
 
Inside Docker for Fedora20/RHEL7
Inside Docker for Fedora20/RHEL7Inside Docker for Fedora20/RHEL7
Inside Docker for Fedora20/RHEL7
 
Introduction to linux containers
Introduction to linux containersIntroduction to linux containers
Introduction to linux containers
 
QNAP COSCUP Container Station
QNAP COSCUP Container StationQNAP COSCUP Container Station
QNAP COSCUP Container Station
 

Destaque

Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...Tim Mackey
 
Developing Automotive Linux
Developing Automotive LinuxDeveloping Automotive Linux
Developing Automotive LinuxAlison Chaiken
 
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013dotCloud
 
Study on Android Emulator
Study on Android EmulatorStudy on Android Emulator
Study on Android EmulatorSamael Wang
 
Simultaneously Leveraging Linux and Android in a GENIVI compliant IVI System
Simultaneously Leveraging Linux and Android in a GENIVI compliant IVI System Simultaneously Leveraging Linux and Android in a GENIVI compliant IVI System
Simultaneously Leveraging Linux and Android in a GENIVI compliant IVI System mentoresd
 
Sierraware ARM hypervisor
Sierraware ARM hypervisor Sierraware ARM hypervisor
Sierraware ARM hypervisor Sierraware
 
The Importance of IVI, GENIVI and Open Source
The Importance of IVI, GENIVI and Open SourceThe Importance of IVI, GENIVI and Open Source
The Importance of IVI, GENIVI and Open Sourcegenivialliance
 
LAS16-507: LXC support in LAVA
LAS16-507: LXC support in LAVALAS16-507: LXC support in LAVA
LAS16-507: LXC support in LAVALinaro
 
Developing the Next Generation Embedded HMIs
Developing the Next Generation Embedded HMIs Developing the Next Generation Embedded HMIs
Developing the Next Generation Embedded HMIs mentoresd
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation Jiann-Fuh Liaw
 
Linaro connect : Introduction to Xen on ARM
Linaro connect : Introduction to Xen on ARMLinaro connect : Introduction to Xen on ARM
Linaro connect : Introduction to Xen on ARMThe Linux Foundation
 
virtualization and hypervisors
virtualization and hypervisorsvirtualization and hypervisors
virtualization and hypervisorsGaurav Suri
 
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARM
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARMXPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARM
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARMThe Linux Foundation
 

Destaque (20)

LXC入門 - Osc2011 nagoya
LXC入門 - Osc2011 nagoyaLXC入門 - Osc2011 nagoya
LXC入門 - Osc2011 nagoya
 
Embedded Virtualization for Mobile Devices
Embedded Virtualization for Mobile DevicesEmbedded Virtualization for Mobile Devices
Embedded Virtualization for Mobile Devices
 
Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...
 
Developing Automotive Linux
Developing Automotive LinuxDeveloping Automotive Linux
Developing Automotive Linux
 
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
 
Study on Android Emulator
Study on Android EmulatorStudy on Android Emulator
Study on Android Emulator
 
Hypervisor and Nova
Hypervisor and NovaHypervisor and Nova
Hypervisor and Nova
 
Simultaneously Leveraging Linux and Android in a GENIVI compliant IVI System
Simultaneously Leveraging Linux and Android in a GENIVI compliant IVI System Simultaneously Leveraging Linux and Android in a GENIVI compliant IVI System
Simultaneously Leveraging Linux and Android in a GENIVI compliant IVI System
 
Sierraware ARM hypervisor
Sierraware ARM hypervisor Sierraware ARM hypervisor
Sierraware ARM hypervisor
 
Xen Hypervisor
Xen HypervisorXen Hypervisor
Xen Hypervisor
 
The Importance of IVI, GENIVI and Open Source
The Importance of IVI, GENIVI and Open SourceThe Importance of IVI, GENIVI and Open Source
The Importance of IVI, GENIVI and Open Source
 
LAS16-507: LXC support in LAVA
LAS16-507: LXC support in LAVALAS16-507: LXC support in LAVA
LAS16-507: LXC support in LAVA
 
Embedded Hypervisor for ARM
Embedded Hypervisor for ARMEmbedded Hypervisor for ARM
Embedded Hypervisor for ARM
 
Developing the Next Generation Embedded HMIs
Developing the Next Generation Embedded HMIs Developing the Next Generation Embedded HMIs
Developing the Next Generation Embedded HMIs
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation
 
Xvisor: embedded and lightweight hypervisor
Xvisor: embedded and lightweight hypervisorXvisor: embedded and lightweight hypervisor
Xvisor: embedded and lightweight hypervisor
 
Linaro connect : Introduction to Xen on ARM
Linaro connect : Introduction to Xen on ARMLinaro connect : Introduction to Xen on ARM
Linaro connect : Introduction to Xen on ARM
 
Android Virtualization: Opportunity and Organization
Android Virtualization: Opportunity and OrganizationAndroid Virtualization: Opportunity and Organization
Android Virtualization: Opportunity and Organization
 
virtualization and hypervisors
virtualization and hypervisorsvirtualization and hypervisors
virtualization and hypervisors
 
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARM
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARMXPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARM
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARM
 

Semelhante a LXC

Docker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in PragueDocker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in Praguetomasbart
 
Using Docker with OpenStack - Hands On!
 Using Docker with OpenStack - Hands On! Using Docker with OpenStack - Hands On!
Using Docker with OpenStack - Hands On!Adrian Otto
 
Arch Linux Package 的前世今生
Arch Linux Package 的前世今生Arch Linux Package 的前世今生
Arch Linux Package 的前世今生yan12125
 
Isolating an applications using LXC – Linux Containers
Isolating an applications using LXC – Linux ContainersIsolating an applications using LXC – Linux Containers
Isolating an applications using LXC – Linux ContainersVenkat Raman
 
Docker and the Container Ecosystem
Docker and the Container EcosystemDocker and the Container Ecosystem
Docker and the Container Ecosystempsconnolly
 
PostgreSQL and Linux Containers
PostgreSQL and Linux ContainersPostgreSQL and Linux Containers
PostgreSQL and Linux ContainersJignesh Shah
 
Postgre sql linuxcontainers by Jignesh Shah
Postgre sql linuxcontainers by Jignesh ShahPostgre sql linuxcontainers by Jignesh Shah
Postgre sql linuxcontainers by Jignesh ShahPivotalOpenSourceHub
 
Resource Management of Docker
Resource Management of DockerResource Management of Docker
Resource Management of DockerSpeedyCloud
 
Automate drupal deployments with linux containers, docker and vagrant
Automate drupal deployments with linux containers, docker and vagrant Automate drupal deployments with linux containers, docker and vagrant
Automate drupal deployments with linux containers, docker and vagrant Ricardo Amaro
 
Containerization Is More than the New Virtualization
Containerization Is More than the New VirtualizationContainerization Is More than the New Virtualization
Containerization Is More than the New VirtualizationC4Media
 
ExpoQA 2017 Using docker to build and test in your laptop and Jenkins
ExpoQA 2017 Using docker to build and test in your laptop and JenkinsExpoQA 2017 Using docker to build and test in your laptop and Jenkins
ExpoQA 2017 Using docker to build and test in your laptop and JenkinsElasTest Project
 
Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby
Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby
Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby Michelle Antebi
 
Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby
Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael CrosbyDocker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby
Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael CrosbyDocker, Inc.
 
WTF my container just spawned a shell!
WTF my container just spawned a shell!WTF my container just spawned a shell!
WTF my container just spawned a shell!Sysdig
 
Docker 原理與實作
Docker 原理與實作Docker 原理與實作
Docker 原理與實作kao kuo-tung
 
Linux containers and docker
Linux containers and dockerLinux containers and docker
Linux containers and dockerFabio Fumarola
 
Rootless Containers & Unresolved issues
Rootless Containers & Unresolved issuesRootless Containers & Unresolved issues
Rootless Containers & Unresolved issuesAkihiro Suda
 
Tech talk on docker with demo
Tech talk on docker with demoTech talk on docker with demo
Tech talk on docker with demoSandeep Karnawat
 

Semelhante a LXC (20)

Docker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in PragueDocker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in Prague
 
Using Docker with OpenStack - Hands On!
 Using Docker with OpenStack - Hands On! Using Docker with OpenStack - Hands On!
Using Docker with OpenStack - Hands On!
 
Arch Linux Package 的前世今生
Arch Linux Package 的前世今生Arch Linux Package 的前世今生
Arch Linux Package 的前世今生
 
Isolating an applications using LXC – Linux Containers
Isolating an applications using LXC – Linux ContainersIsolating an applications using LXC – Linux Containers
Isolating an applications using LXC – Linux Containers
 
Docker and the Container Ecosystem
Docker and the Container EcosystemDocker and the Container Ecosystem
Docker and the Container Ecosystem
 
PostgreSQL and Linux Containers
PostgreSQL and Linux ContainersPostgreSQL and Linux Containers
PostgreSQL and Linux Containers
 
Postgre sql linuxcontainers by Jignesh Shah
Postgre sql linuxcontainers by Jignesh ShahPostgre sql linuxcontainers by Jignesh Shah
Postgre sql linuxcontainers by Jignesh Shah
 
Resource Management of Docker
Resource Management of DockerResource Management of Docker
Resource Management of Docker
 
Automate drupal deployments with linux containers, docker and vagrant
Automate drupal deployments with linux containers, docker and vagrant Automate drupal deployments with linux containers, docker and vagrant
Automate drupal deployments with linux containers, docker and vagrant
 
#WeSpeakLinux Session
#WeSpeakLinux Session#WeSpeakLinux Session
#WeSpeakLinux Session
 
Containerization Is More than the New Virtualization
Containerization Is More than the New VirtualizationContainerization Is More than the New Virtualization
Containerization Is More than the New Virtualization
 
ExpoQA 2017 Using docker to build and test in your laptop and Jenkins
ExpoQA 2017 Using docker to build and test in your laptop and JenkinsExpoQA 2017 Using docker to build and test in your laptop and Jenkins
ExpoQA 2017 Using docker to build and test in your laptop and Jenkins
 
Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby
Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby
Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby
 
Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby
Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael CrosbyDocker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby
Docker 1.11 Meetup: Containerd and runc, by Arnaud Porterie and Michael Crosby
 
Ansible docker
Ansible dockerAnsible docker
Ansible docker
 
WTF my container just spawned a shell!
WTF my container just spawned a shell!WTF my container just spawned a shell!
WTF my container just spawned a shell!
 
Docker 原理與實作
Docker 原理與實作Docker 原理與實作
Docker 原理與實作
 
Linux containers and docker
Linux containers and dockerLinux containers and docker
Linux containers and docker
 
Rootless Containers & Unresolved issues
Rootless Containers & Unresolved issuesRootless Containers & Unresolved issues
Rootless Containers & Unresolved issues
 
Tech talk on docker with demo
Tech talk on docker with demoTech talk on docker with demo
Tech talk on docker with demo
 

Último

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Último (20)

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

LXC

  • 2. Who am I • Software Engineer at Canonical • Skills – Legacy, EFI BIOS – Linux Kernel – Android framework & HAL & Apps – Window Apps with wxPython – Linux Desktop Stack • Links – Blog, LinkedIn, github 2
  • 4. Virtualization • Hardware Virtualization – Full: VirtualBox – Para: Xen, KVM • Software – Operating system-level virtualization • LXC • OpenVZ • Linux VServer • FreeBSD Jails • chroot 4 Containers Hardware OS P0 Pn P0 Pn
  • 5. LXC • LXC (LinuX Containers) – Run a Linux system within another Linux system • Container – a group of processes on a Linux box, put together in an isolated environment • Inside the box, it looks like a VM • Outside the box, it looks like normal processes 5
  • 6. Benefit • Speed - fast – Boots, create VM, deploy tasks • Footprint - small – aufs or overlayfs • Virtualization – Own network interface – Own filesystem – Isolation and security – Isolation and resource usage 6
  • 7. Use Cases • Continuous Integration – Run 100 tests in 100 VMs • Escape dependency hell • Do whatever you did in VMs – But faster 7
  • 9. • Ubuntu 12.04.2 9 $ sudo apt-get install lxc $ sudo lxc-create -t ubuntu -n u1 $ sudo lxc-start -n u1 -d $ sudo lxc-console -n u1 username/name: ubuntu ^aq $ sudo lxc-list $ sudo lxc-info -n u1 $ sudo lxc-shutdown -n u1 $ sudo lxc-destroy -n u1
  • 10. Cheat Sheet • lxc-create - create system container • lxc-destroy - destroy container • lxc-start - start sys container • lxc-stop - stop sys container • lxc-shutdown - safely shut down a container • lxc-execute - Run command in a app container • lxc-start-ephemeral - start an one-time container • lxc-ls - shorter output than lxc-list • lxc-list - List all containers • lxc-info - Print info on the state of a container • lxc-monitor - Monitor state • lxc-wait - Wait for a state change • lxc-restore - restore containers from backups made by lxc-backup • lxc-backup - back up the root filesystems • lxc-freeze - freeze a running container • lxc-unfreeze - unfreeze a frozen container • lxc-cgroup - View and set container control group settings • lxc-netstat - Execute netstat in a running container • lxc-ps - View process info in a running container 10
  • 11. create x destroy • lxc-create -n {ctx-name} -t {template name} – $ sudo lxc-create -n u1 -t ubuntu – $ sudo lxc-create -n u2 -t ubuntu -- -r raring – Templates are in /usr/lib/lxc/lxc-* – When first created, a base filesystem will put in /var/cache/lxc/ – Then copy a instance to /var/lib/lxc/{name}/ • config • fstab • rootfs/ • lxc-destroy -n {name} 11
  • 12. start x stop x shutdown • lxc-start -n {name} [-d] [-o logfile] [--logpriority=LEVEL] – Start a system-level container (/sbin/init) • lxc-shutdown -n name [-w] [-r] [-t timeout] – Cleanly shut down a container. • Send SIGPWR • If not stopped, call lxc-stop which sends SIGKILL – -w: wait for shutdown to complete. – -r: reboot (ignore -w). – -t timeout: wait at most timeout seconds (implies -w), then kill the container. • lxc-stop -n {name} 12
  • 13. execute x start-ephermal • lxc-execute -n {NAME} -- {COMMAND} – Run a command in application-level container • lxc-start-ephemeral [-d] [-u user] [-S key] -o {orig} -- [COMMAND] – Runs an ephemeral (one-off) container – $ sudo lxc-start-ephemeral -u ubuntu -o u1 -- uname -a – Options: • orig - name of the original container • user - the user to connect to the container as • key - the path to the SSH key to use to connect • -d - run in the background 13
  • 14. cgroup • lxc-cgroup -n {name} {subsystem} {value} – View and set container control group settings – $ sudo lxc-cgroup -n u1 memroy.limit_in_bytes 256M – $ lxc-cgroup -n u1 cpu.shares 512 • maximum is 1024 – $ lxc-cgroup -n u1 cpuset.cpus 0,3 – Configure - /var/lib/lxc/{name}/config, such as • lxc.cgroup.memory.limit_in_bytes = 256M 14
  • 15. clone x backup x restore • sudo lxc-clone -o {orig} -n {new} • sudo lxc-backup {name} {number} • sudo lxc-restore {name} {number} 15
  • 17. Docker Docker can help you easily create lightweight, portable, self-sufficient containers from any application 17
  • 18. Deploy Remote Desktop 18 $ sudo apt-get install linux-image-extra-`uname -r` $ sudo add-apt-repository ppa:dotcloud/lxc-docker $ sudo apt-get update $ sudo apt-get install lxc-docker $ docker run -i -t ubuntu /bin/bash $ docker build -t vpsee/docker-desktop git://github.com/rogaha/docker- desktop.git $ docker images $ docker run vpsee/docker-desktop $ docker port a581df505cb9 22 $ docker ps $ ssh -XC docker@localhost -p 49153 ./docker-desktop $ xpra --ssh="ssh -p 49153" attach ssh:docker@localhost:10 http://www.vpsee.com/2013/07/use-docker-and-lxc-to-build-a-desktop/
  • 19. 19 Dockerfile allow you to automate the steps you would normally manually take to create an image.
  • 20. Juju Automate your cloud infrastructure Configure, manage, maintain, deploy and scale efficiently with best-practice Charms on any public, private or hybrid cloud from a powerful GUI or the command-line. 20
  • 21. Deploy WordPress 21 $ sudo apt-add-repository ppa:juju/stable $ sudo apt-get update $ sudo apt-get install lxc mongodb-server juju juju-core $ juju init $ sed -i ‘s/default: amazon/default: local/’ ~/.juju/environments.yaml $ sudo juju bootstrap $ sudo juju deploy wordpress $ sudo juju deploy mysql $ sudo juju add-relation wordpress mysql $ sudo juju expose wordpress $ sudo juju status https://juju.ubuntu.com/docs/
  • 22. 22
  • 23. $ sudo juju status environment: local machines: "0": agent-state: started agent-version: 1.14.1.1 dns-name: 10.0.3.1 instance-id: localhost series: precise "2": agent-state: started agent-version: 1.14.1.1 dns-name: 172.16.0.5 instance-id: doro-local-machine-2 series: precise "3": agent-state: started agent-version: 1.14.1.1 dns-name: 172.16.0.5 instance-id: doro-local-machine-3 series: precise services: mysql: charm: cs:precise/mysql-27 exposed: false relations: cluster: - mysql db: - wordpress units: mysql/0: agent-state: started agent-version: 1.14.1.1 machine: "2" public-address: 10.0.3.162 wordpress: charm: cs:precise/wordpress-18 exposed: false relations: db: - mysql loadbalancer: - wordpress units: wordpress/0: agent-state: error agent-state-info: 'hook failed: "install"' agent-version: 1.14.1.1 machine: "3" public-address: 10.0.3.118 23
  • 24. $ sudo juju destroy-environment $ sudo apt-get purge juju juju-core mongo- server 24
  • 25. Vagrant Development environments made easy Create and configure lightweight, reproducible, and portable development environments. 25
  • 26. Create Ubuntu 12.04 64-bits 26 $ vagrant box add precise64 http://files.vagrantup.com/precise64.box $ mkdir my_box $ cd my_box $ vagrant init precise64 $ vagrant up $ vagrant ssh $ vagrant suspend $ vagrant halt $ vagrant destroy vagrant-lxc, https://github.com/fgrehm/vagrant-lxc
  • 28. Get Code • $ apt-get source lxc • configure – /etc/lxc/lxc.conf – /etc/lxc/auto • init script – /etc/default/lxc – /etc/init/lxc.conf – /etc/init/lxc-net.conf – /etc/dnsmasq.d-available/lxc 28
  • 29. Namespaces • Partition essential kernel structures to create virtual environments • Types – pid – net – ipc – mnt – uts (hostname) – user 29
  • 30. Create Namespaces • flags to the system call clone() – mnt: CLONE_NEWNS – uts: CLONE_NEWUTS – ipc: CLONE_NEWIPC – pid: CLONE_NEWPID – net: CLONE_NEWNET – user: CLONE_NEWUSER • command unshare – unshare [-m] [-u] [-i] [-n] <program> [args...] 30
  • 32. Network • Each container has its own interface, routing table, iptables rules… • Communication between containers via pairs of veth interface • /etc/init/lxc-net.conf: iptables, dnsmasq… 32 [1] $ sudo unshare --net bash [2] $ echo $$ [1] $ sudo ip link add name lxcbr0 type veth peer name vethdoro [1] $ ip link set vethdoro netns <PID> [2] $ ip link set vethdoro name eth0 [2] $ ifconfig eth0 192.168.1.2 [2] $ ifconfig lo 127.0.0.1 [1] $ ifconfig addif vethdoro
  • 33. Mount • Deluxe chroot()  pivot_root() • Filesystems mounted in a mnt namespace are visible only in this namespace • You need to remount special filesystem – procfs – devpts • Commands – unshare --mount <program> – mount {--make-[r]shared | --make-[r]slave | -- make -- [r]private | --make-unbindable} <mount-object> 33 http://www.ibm.com/developerworks/linux/library/l-mount-namespaces/index.html
  • 34. cgroup • Everything exposed through filesystem – cgroup on /sys/fs/cgroup type tmpfs (rw,relatime,mode=755) – cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,relatime,cpuset) – cgroup on /sys/fs/cgroup/cpu type cgroup (rw,relatime,cpu) – cgroup on /sys/fs/cgroup/cpuacct type cgroup (rw,relatime,cpuacct) • Create a cgroup – mkdir -p /sys/fs/cgroup/cpu/lxc/u1 – Add PID to cgroup: echo $PID > /sys/fs/cgroup/cpu/lxc/u1/tasks – Limit: echo 512 > /sys/fs/cgroup/cpu/lxc/u1/cpu.shares 34
  • 35. Limit & Account • CPU – cpu.shares – cpustat.usage – cpuset.cpus • Memory – memory.[soft_]limit_in_bytes – memory.stat • Block I/O – blkio.throttle.{read,write}.{iops,bps}.device • RTFM: Documentation/cgroup/* 35

Notas do Editor

  1. lxc-setuidlxc-listlxc-checkpointlxc-checkconfiglxc-consolelxc-unsharelxc-setcaplxc-versionlxc-clonelxc-executelxc-executelxc-unshare