Docker Gateways
Docker Gateways
Docker Gateways
1. Docker
1. Docker Container
2. Docker Key Concepts
3. Docker Internals
4. Docker Architecture Linux Vs. OS X
5. Docker Architecture Windows
6. Docker Architecture Linux (Docker Daemon and Client)
7. Anatomy of Dockerfile
8. Building a Docker Image
9. Creating and Running a Docker Container
10. Invoking Docker Container using Java ProcessBuilder
2. Linux Containers
Docker containers are Linux Containers 3
DOCKER
CGROUPS NAMESPACES IMAGES
CONTAINER
• Docker Registries
• Docker registries hold images.
• These are public or private stores from which you upload or download images.
• The public Docker registry is called Docker Hub.
• It provides a huge collection of existing images for your use.
• These can be images you create yourself or you can use images that others have
previously created.
• Docker registries are the distribution component of Docker.
Docker Architecture Linux Vs. OS X 5
• In OS X, the Docker host address is the address of the Linux VM. When you start
the boot2docker process, the VM is assigned an IP address. Under boot2docker
ports on a container map to ports on the VM.
Docker – Somewhere in the Future …… 6
Searching in
the docker
registry for
images.
Images in your
local registry
after the build
or directly
pulled from
docker
registry.
Analyzing “docker run –it ubuntu /bin/bash” command 9
The COPY instruction copies new files or directories from <src> and adds COPY hom* /mydir/
COPY them to the filesystem of the container at the path <dest>. COPY hom?.txt /mydir/
The ENV instruction sets the environment variable <key> to the value
ENV JAVA_HOME /JDK8
ENV <value>. This value will be in the environment of all "descendent" Dockerfile
ENV JRE_HOME /JRE8
commands and can be replaced inline in many as well.
The EXPOSE instructions informs Docker that the container will listen on the
specified network ports at runtime. Docker uses this information to
EXPOSE interconnect containers using links and to determine which ports to expose
EXPOSE 8080
to the host when using the –P flag with docker client.
Anatomy of a Dockerfile 11
docker ps
-a Show all the containers. Only running containers are shown by default
-q Only display the Numeric IDs
-s Display the total file sizes
Provide Filters to show containers.
-f -f status=exited
-f exited=100
-l Show only the latest Container.
When you execute docker command using Java ProcessBuilder API never use
run with –it (for interactive and terminal). This will block the container from
exiting, unless you want to have an interactive session..
Ex. docker run applifire/maven:jdk7 pom.xml
If you are using a shell script to invoke the docker container then refer the
following to handle Linux and OS X environments.
Boot2Docker
Settings for
OS X
$? to get the
exit code of
previous
command
LinuX Container
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations :
By Boden Russell – IBM Technology Services ([email protected])
21
What’s Linux container
Linux Containers (LXC for LinuX Containers) are
Containerization of:
GFlops
150
• Minimal per container penalty 100
50
11
13
15
17
19
21
23
25
27
29
31
BM
Supported with OOTB modern Linux kernel vcpus
Growing in popularity
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Hypervisors vs. Linux containers 23
Containers share the OS kernel of the host and thus are lightweight.
However, each container must have the same OS kernel.
Containers are isolated,
but share OS and,
where appropriate, libs /
bins.
Ap Ap Ap Ap
p p p p
Ap Ap Ap Ap
Bins / libs Bins / libs
p p p p
Operating Operating Ap Ap Ap Ap
Bins / libs Bins / libs System System p p p p
Operating Operating Virtual Machine Virtual Machine
System System Bins / libs Container
Virtual Machine Virtual Machine Hypervisor Container
Bins / libs
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Technology Stack 24
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux cgroups 25
History
• Work started in 2006 by google engineers
• Merged into upstream 2.6.24 kernel due to wider spread LXC usage
• A number of features still a WIP
Functionality
• Access; which devices can be used per cgroup
• Resource limiting; memory, CPU, device accessibility, block I/O, etc.
• Prioritization; who gets more of the CPU, memory, etc.
• Accounting; resource usage per cgroup
• Control; freezing & check pointing
• Injection; packet tagging
Usage
• cgroup functionality exposed as “resource controllers” (aka “subsystems”)
• Subsystems mounted on FS
• Top-level subsystem mount is the root cgroup; all procs on host
• Directories under top-level mounts created per cgroup
• Procs put in tasks file for group assignment
• Interface via read / write pseudo files in group
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux cgroup subsystems 26
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux cgroups FS layout 27
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux cgroups Pseudo FS Interface 28
|-- blkio
| |-- blkio.io_merged
| |-- blkio.io_queued
| |-- blkio.io_service_bytes
| |-- blkio.io_serviced
| |-- blkio.io_service_time
| |-- blkio.io_wait_time echo "8:16 1048576“ >
| |-- blkio.reset_stats blkio.throttle.read_bps_device
| |-- blkio.sectors
| |-- blkio.throttle.io_service_bytes
| |-- blkio.throttle.io_serviced
| |-- blkio.throttle.read_bps_device
| |-- blkio.throttle.read_iops_device
App
| |-- blkio.throttle.write_bps_device
| |-- blkio.throttle.write_iops_device
| |-- blkio.time cat blkio.weight_device
dev weight
| |-- blkio.weight
8:1 200
App
| |-- blkio.weight_device
| |-- cgroup.clone_children 8:16 500
| |-- cgroup.event_control App
| |-- cgroup.procs
| |-- notify_on_release
| |-- release_agent
| `-- tasks
|-- cpu
| |-- ...
|-- ...
`-- perf_event
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux cgroups: CPU Usage 29
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux cgroups: CPU Pinning 30
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux cgroups: Device Access 31
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Realization: Linux cgroups 32
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux namespaces 33
History
• Initial kernel patches in 2.4.19
• Recent 3.8 patches for user namespace support
• A number of features still a WIP
Functionality
• Provide process level isolation of global resources
• MNT (mount points, file systems, etc.)
• PID (process)
• NET (NICs, routing, etc.)
• IPC (System V IPC resources)
• UTS (host & domain name)
• USER (UID + GID)
• Process(es) in namespace have illusion they are the only processes on the
system
• Generally constructs exist to permit “connectivity” with parent namespace
Usage
• Construct namespace(s) of desired type
• Create process(es) in namespace (typically done when creating namespace)
• If necessary, initialize “connectivity” to parent namespace
• Process(es) in name space internally function as if they are only proc(s) on
system
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux namespaces: Conceptual Overview 34
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux namespaces: MNT namespace 35
• Hostname UTS NS
globalhost
• NIS domain name rootns.com
“red” namespace
UTS NS
redhost
redns.com
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux namespaces: PID namespace 37
“red” namespace
PID NS
PID COMMAND
1 /bin/bash
2 python
3 node
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux namespaces: IPC namespace 38
System V IPC object & POSIX message queue “global” (i.e. root)
namespace
isolation between namespaces IPC NS
SHMID OWNER
• Semaphores 32452
43321
root
boden
• Signals IPC NS
SEMID OWNER
• Sockets (if no NET namespace) 0 root
IPC NS
SHMID OWNER
SEMID OWNER
MSQID OWNER
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux namespaces: NET namespace 39
• ports “green”
namespace
• Etc NET NS
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux namespaces: USER namespace 40
A long work in progress – still development for XFS “global” (i.e. root)
namespace
and other FS support
USER NS
• Significant security impacts root 0:0
ntp 104:109
• A handful of security holes already found + fixed Mysql 105:110
boden 106:111
Two major features provided:
• Map UID / GID from outside the container to UID /
“green”
GID inside the container namespace
• Permit non-root users to launch LXCs USER NS
• Distro’s rolling out phased support, with UID / GID root 0:0
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Realization: Linux namespaces 41
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux namespaces & cgroups: Availability 42
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux chroot vs pivot_root 44
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Realization: Images 45
LXC images provide a flexible means to deliver only what you need – lightweight and minimal footprint
Basic constraints
• Same architecture
• Same endian
• Linux’ish Operating System; you can run different Linux distros on same host
Image types
• System; images intended to virtualize Operating System(s) – standard distro root FS less
the kernel
• Application; images intended to virtualize application(s) – only package apps +
dependencies (aka JeOS – Just enough Operating System)
Bind mount host libs / bins into LXC to share host resources
Container image init process
• Container init command provided on invocation – can be an application or a full fledged init
process
• Init script customized for image – skinny SysVinit, upstart, etc.
• Reduces overhead of lxc start-up and runtime foot print
Various tools to build images
• SuSE Kiwi
• Debootstrap
• Etc.
LXC tooling options often include numerous image templates
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux Security Modules & MAC 46
Linux Security Modules (LSM) – kernel modules which provide a framework for
Mandatory Access Control (MAC) security implementations
MAC vs DAC
• In MAC, admin (user or process) assigns access controls to subject / initiator
• Most MAC implementations provide the notion of profiles
• Profiles define access restrictions and are said to “confine” a subject
• In DAC, resource owner (user) assigns access controls to individual resources
Existing LSM implementations include: AppArmor, SELinux, GRSEC, etc.
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Linux Capabilities & Other Security Measures 47
Linux capabilities
• Per process privileges which define operational (sys call) access
• Typically checked based on process EUID and EGID
• Root processes (i.e. EUID = GUID = 0) bypass capability checks
Capabilities can be assigned to LXC processes to restrict
Other LXC security mitigations
• Reduce shared FS access using RO bind mounts
• Keep Linux kernel up to date
• User namespaces in 3.8+ kernel
• Allow to launch containers as non-root user
• Map UID / GID inside / outside of container
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Realization 48
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Tooling 49
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Industry Tooling 50
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Libvirt-lxc 51
No snapshotting, templates…<memory>32768</memory>
<os> <type>exe</type> <init>/init</init> </os>
<vcpu>1</vcpu>
<clock offset='utc'/>
OpenStack support since Grizzly <on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
No VNC <devices>
No Cinder support in Grizzly <emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount'> <source dir='/opt/vm-1-root'/> <target dir='/'/> </filesystem>
Config drive not supported <interface type='network'> <source network='default'/> </interface>
<console type='pty' />
Alternative means of accessing metadata</devices>
Attached disk rather than http calls </domain>
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC (tools) 52
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Commoditization: docker 53
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Docker vs. LXC vs. Hypervisor 54
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Docker: LXC Virtualization? 55
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Orchestration & Management 56
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Docker in OpenStack 57
Introduced in Havana
• A nova driver to integrate with docker REST API
• A Glance translator to integrate containers with Glance
• A docker container which implements a docker registry API
The claim is that docker will become a “group A” hypervisor
• In it’s current form it’s effectively a “tech preview”
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Evaluation 58
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Runtime Performance Benefits - CPU 59
250
200
GFlops
150
100
50
0
1
11
13
15
17
19
21
23
25
27
29
31
BM
vcpus
220.9 220.77
@ 31 vcpu 220.5 Bare metal
@32 vcpu
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Runtime Performance Benefits – I/O 60
I/O throughput
1000 Series1
500
0
lxc write bare metal lxc read bare metal
write read
test
Rw=Write Rw=Write
Size=1024m
Size=1024m
Bs=128mb
Bs=128mb
direct=1
direct=1
sync=1
sync=1
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Runtime Performance Benefits – Block I/O 61
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Density & Footprint – libvirt-lxc 62
Using libvirt lxc on RHEL 6.4, we found that empty container overhead was just 840 bytes. A container could be started in
about 330ms, which was an I/O bound process
This represents the lower limit of lxc footprint
Containers ran /bin/sh
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Density & Footprint – Docker 63
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Workload Isolation: Examples 64
We used fio with oflag=sync, direct to test the ability to cap the
reads:
• No read limit
READ: io=131072KB, aggrb=84726KB/s, minb=86760KB/s, maxb=86760KB/s, mint=1547msec,
maxt=1547msec
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
OpenStack VM Operations 65
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
Who’s Using LXC 66
Google app engine & infra is said to be using some form of LXC
RedHat OpenShift
dotCloud (now docker inc)
CloudFoundry (early versions)
Rackspace Cloud Databases
• Outperforms AWS (Xen) according to perf results
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Gaps 67
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC: Use Cases For Traditional VMs 68
There are still use cases where traditional VMs are warranted.
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Recommendations 69
If you are just starting with LXC and don’t have in-depth skillset
• Start with LXC for private solutions (trusted code)
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
LXC Resources 70
https://www.kernel.org/doc/Documentation/cgroups/
http://www.blaess.fr/christophe/2012/01/07/linux-3-2-cfs-cpu-bandwidth-english-version/
http://atmail.com/kb/2009/throttling-bandwidth/
https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/ch-
Subsystems_and_Tunable_Parameters.html
http://www.janoszen.com/2013/02/06/limiting-linux-processes-cgroups-explained/
http://www.mattfischer.com/blog/?p=399
http://oakbytes.wordpress.com/2012/09/02/cgroup-cpu-allocation-cpu-shares-examples/
http://fritshoogland.wordpress.com/2012/12/15/throttling-io-with-linux/
https://lwn.net/Articles/531114/
https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt
http://www.ibm.com/developerworks/library/l-mount-namespaces/
http://blog.endpoint.com/2012/01/linux-unshare-m-for-per-process-private.html
http://timothysc.github.io/blog/2013/02/22/perprocess/
http://www.evolware.org/?p=293
http://s3hh.wordpress.com/2012/05/10/user-namespaces-available-to-play/
http://libvirt.org/drvlxc.html
https://help.ubuntu.com/lts/serverguide/lxc.html
https://linuxcontainers.org/
https://wiki.ubuntu.com/AppArmor
http://linux.die.net/man/7/capabilities
http://docs.openstack.org/trunk/config-reference/content/lxc.html
https://wiki.openstack.org/wiki/Docker
https://www.docker.io/
http://marceloneves.org/papers/pdp2013-containers.pdf
http://openvz.org/Main_Page
http://criu.org/Main_Page
© Realizing Linux Containers (LXC) Building Blocks, Underpinnings & Motivations : By Boden Russell – IBM Technology Services ([email protected])
71
Thank You…..
Thanks to :
Boden Russell – IBM Technology Services
([email protected])
For the fantastic presentation on LinuX Containers