5. Inside Docker
Docker Daemon
Libcontainer
cgroups namespaces
AUFS
BTRFS
dm-thinp
VFS
KernelUserSpace
Linux Container
resource(cpu, mem)
limitation/isolation
Environment( process/network)
isolation
Copy on Write
File System
6. Inside Docker: AUFS File System
Layer 2
Layer 1
Base Image
Writable Layer
Container
Layer 1
Base Image
Writable Layer
Container
Snapshot
Container A Container B
Writable Layer
A
Writable Layer
B
Layer 2 (e.g. Configuration)
Layer 1 (e.g. MySQL)
Base Image (e.g. Ubuntu)
S
h
a
r
e
d
P
r
i
v
7. Killer Apps with Docker
Microservice Architecture
Microservice is a loosely coupled service oriented architecture with bounded contexts
10. Setup Local Docker Environment
Install Docker on Ubuntu Linux:
adminuser@adminuser-VirtualBox:~$ sudo apt-get install -y docker.io
. . . . . .
Setting up docker.io (1.5.0~dfsg1-1ubuntu2) ...
Adding group `docker' (GID 132) ...
Done.
adminuser@adminuser-VirtualBox:~$ sudo service docker restart
adminuser@adminuser-VirtualBox:~$
Check Local Docker Environment:
adminuser@adminuser-VirtualBox:~$ sudo docker info
Containers: 0
Images: 0
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 0
Execution Driver: native-0.2
Kernel Version: 3.19.0-20-generic
Operating System: Ubuntu 15.04
CPUs: 1
Total Memory: 4.844 GiB
Name: adminuser-VirtualBox
ID: 7U44:LJUS:N4MT:LTUN:MRMW:JRG6:QURR:VEVF:BBJI:ISZQ:CISK:EGME
WARNING: No swap limit support
11. Setup Local Docker Environment
Pulling Docker Images from Docker Hub:
adminuser@adminuser-VirtualBox:~$ sudo docker pull ubuntu:15.04
Pulling repository ubuntu
82554298ff4f: Download complete
b8b73eaafc6e: Download complete
9f5beeea5d8a: Download complete
08ab09376d9a: Download complete
Status: Downloaded newer image for ubuntu:15.04
adminuser@adminuser-VirtualBox:~/dockerprjs$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 15.04 82554298ff4f 3 days ago 131.4 MB
ubuntu vivid 82554298ff4f 3 days ago 131.4 MB
ubuntu vivid-20150930 82554298ff4f 3 days ago 131.4 MB
Start Docker Container using “run” command:
adminuser@adminuser-VirtualBox:~$ sudo docker run -i -t ubuntu:15.04 /bin/bash
root@6bff442a89ad:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@6bff442a89ad:/# exit
exit
12. Building Docker Image with Dockerfile
Dockerfile is DSL to build Docker Image
A sample Dockerfile building a Play Web Server with AngularJS Front-end:
FROM ubuntu:15.04
MAINTAINER Jian Wu
ENV REFRESHED_AT 2015-10-12
RUN DEBIAN_FRONTEND=noninteractive apt-get update -y
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y wget
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y openjdk-7-jdk
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y libjansi-java
RUN java -version
RUN wget www.scala-lang.org/files/archive/scala-2.10.5.deb
RUN dpkg -i scala-2.10.5.deb
RUN wget --referer='http://www.scala-sbt.org/0.13/tutorial/Installing-sbt-on-Linux.html' --local-encoding=UTF-8
https://dl.bintray.com/sbt/debian/sbt-0.13.8.deb
RUN dpkg -i sbt-0.13.8.deb
EXPOSE 9000
ADD spark-dataframe-report-server /dfreportserver
WORKDIR /dfreportserver
RUN sbt clean compile
CMD sbt run
13. Building Docker Image using “build” command:
adminuser@adminuser-VirtualBox:~/dockerprjs$ sudo docker build -t dfreportserverv1 .
. . . . . .
[success] Total time: 194 s, completed Oct 12, 2015 10:34:34 PM
---> f90b60f7cff6
Removing intermediate container 76a43d7db31a
Step 16 : CMD sbt run
---> Running in cfcc978b5781
---> 9101373c8e80
Removing intermediate container cfcc978b5781
Successfully built 9101373c8e80
adminuser@adminuser-VirtualBox:~/dockerprjs$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
dfreportserverv1 latest 9101373c8e80 56 seconds ago 836.9 MB
ubuntu vivid-20150930 82554298ff4f 4 days ago 131.4 MB
ubuntu 15.04 82554298ff4f 4 days ago 131.4 MB
ubuntu vivid 82554298ff4f 4 days ago 131.4 MB
Building Docker Image with Dockerfile
14. Running Docker Container with Locally Built Image
Start Docker Container using “run” command:
adminuser@adminuser-VirtualBox:~$ sudo docker run -it -p 9000:9000
dfreportserverv1
[info] Loading project definition from /dfreportserver/project
[info] Set current project to spark-dataframe-report-server (in build
file:/dfreportserver/)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in
[jar:file:/root/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-c
lassic-1.1.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/root/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.
7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an
explanation.
SLF4J: Actual binding is of type
[ch.qos.logback.classic.util.ContextSelectorStaticBinder]
--- (Running the application, auto-reloading is enabled) ---
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
(Server started, use Ctrl+D to stop and go back to the console...)
15. Docker Volume
Docker Volume let sys admin mount a directory from the Docker daemon’s host
into a container as a data volume
16. Docker Networking
Bridge Mode (Default):
“docker0” virtual interface is created as
“Ethernet Bridge” to routing network traffic
between containers and Docker Host
Host Mode:
Container directly using Host Network
18. Docker Hub
(Dockercon SF 2015)
Major features:
-- Public and Private Docker repositories
-- Official Repositories
-- Collaborators, Organizations and Groups
-- Automated builds
-- Webhooks
Docker Hub (hub.docker.com) is a cloud registry service for sharing application
and automating workflows.