14. Load
• typical laptop can run 10-100 containers
• typical server can run 100-1000 containers
image credits: Nicole Munro -NEW ZEALAND DEFENCE FORCE
20. LXC vs OpenVZ
OpenVZ LXC
works on non-patched kernel no yes
limit memory usage yes yes
limit kernel memory usage yes no
limit disk IO no yes
limit disk usage yes partial
checkpointing yes not yet
live migration yes no*
* workaround via criu.org
• disk limiting is possible with LVM however with
lower IO performance
23. LXC performance
Miguel G. Xavier, Marcelo V. Neves, Fabio D. Rossi, Tiago C. Ferreto, Timoteo Lange, and Cesar A. F. De Rose. 2013.
Performance Evaluation of Container-Based Virtualization for High Performance Computing Environments. In
Proceedings of the 2013 21st Euromicro International Conference on Parallel, Distributed, and Network-Based
Processing (PDP ’13). IEEE Computer Society, Washington, DC, USA, 233-240
24. LXC
$ lxc-create -t ubuntu -n linux-days
Checking cache download in /var/cache/lxc/trusty/rootfs-amd64 ...
Installing packages in template: ssh,vim,language-pack-en
Downloading ubuntu trusty minimal ...
W: Target architecture is the same as host architecture; disabling
QEMU support
I: Running command: debootstrap --arch amd64 --verbose --components=main,
universe --include=ssh,vim,language-pack-en trusty /var/cache/lxc/
trusty/partial-amd64
$ lxc-ls -f
NAME STATE IPV4 IPV6 AUTOSTART
-----------------------------------------------
linux-days STOPPED - - NO
25. LXC network
$ vim /var/lib/lxc/linux-days/rootfs/etc/network/interfaces
• we can edit directly container’s files
auto eth0
iface eth0 inet static
address 10.0.3.12
netmask 255.255.255.0
network 10.0.3.0
gateway 10.0.3.1
dns-nameservers 10.0.3.1 8.8.8.8
26. LXC memory and CPU limits
$ vim /var/lib/lxc/linux-days/config
• limiting CPU and memory
lxc.cgroup.memory.limit_in_bytes = 2048M
lxc.cgroup.cpuset.cpus = 3-6
28. LXC disk
• number of bytes transferred to/from the disk by the
group
cat /sys/fs/cgroup/lxc/linux-days/blkio.io_service_bytes
8:0 Write 0
8:0 Sync 67913826304
8:0 Async 0
8:0 Total 67913826304
8:16 Read 93198610432
8:16 Write 0
8:16 Sync 93198610432
8:16 Async 0
8:16 Total 93198610432
Total 161112436736
36. Docker makefile
$ make build
$ make run
build:
docker build -t deric/my-nginx .
run:
docker run --name hello-nginx -d -p 8080:80 my-nginx
test:
curl localhost:8080
clean:
rm -rf node_modules
.PHONY: build run test clean
37. Example 2: node.js
• node.js hello world base on debian:stable
• CMD line is executed same way as:
$ docker run -i -t debian:stable cmd
FROM debian:stable
RUN apt-get update apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup | bash -
RUN apt-get install -y nodejs
# App
ADD . /web
# Install app dependencies
RUN cd /web; npm install
EXPOSE 8080
CMD [node, /web/index.js]
• source code: https://github.com/deric/
docker-nodejs-helloworld
38. Docker ps
• running processes
$ docker ps
CONTAINER ID IMAGE COMMAND PORTS NAMES
00f65e6387e1 my-nginx:latest nginx -g daemon of 443/tcp, 0.0.0.0:8080-80/tcp hello-nginx
• all processes including exited
$ docker ps -a
42. Storage filesystems
union snapshotting copy-on-write
block devices
provisioning superfast fast fast
changing small files supercheap cheap costly
changing large files slow fast fast
diffing superfast superfast slow
memory usage efficient efficient inefficient
drawbacks random quirks ZFS not mainline higher disk usage
43. Remove image
• remove all exited processes (containers):
$ docker rm $(docker ps -a -q)
44. Remove image
• single image:
$ docker rmi my_image
• all images
$ docker rmi $(docker images -q)