Docker introduction.
References : The Docker Book : Containerization is the new virtualization
http://www.amazon.in/Docker-Book-Containerization-new-virtualization-ebook/dp/B00LRROTI4/ref=sr_1_1?ie=UTF8&qid=1422003961&sr=8-1&keywords=docker+book
2. Agenda
• Introduction
• Docker
Components
A. The
Docker
Client
and
Server
B. Docker
Images
C. Registries
D. Docker
Containers
• What
can
you
use
Docker
for?
• Docker
Installation
• Docker
User
Interface
• Basic
Commands
• Demo
• Questions
3. Introduction
to
Docker
“Docker
is
an
open-‐source
engine
that
automates
the
deployment
of
applications
into
containers.
It
adds
an
application
deployment
engine
on
top
of
a
virtualised
container
execution
environment.”
It
was
written
by
the
team
at
Docker,
Inc
(formerly
dotCloud
Inc,
an
early
player
in
the
Platform-‐as-‐a-‐Service
(PAAS)
market),
and
released
by
them
under
the
Apache
2.0
license.
4. Docker’s
Mission
is
to
provide
1. An
easy
and
lightweight
way
to
model
reality
Docker
is
fast,
It
relies
on
copy-‐on-‐write
Model.
So,
that
making
changes
to
your
application
is
also
incredibly
fast:
only
what
you
want
to
change
will
change.
2. A
logical
Segregation
of
Duties
With
Docker,
Developers
care
about
the
application
running
inside
the
containers,
and
Operations
care
about
managing
the
containers.
3. Fast,
efficient
development
life
cycle
Docker
aims
to
reduce
the
cycle
time
between
code
being
written
and
code
being
tested,
deployed
and
used.
4. Encourage
Service
Oriented
Architecture
Docker
encourage
service
oriented
architecture,
It
recommends
that
each
container
run
a
single
application
or
Process.
5. Docker
Components
:
The
Docker
Client
and
Server
Docker
is
a
client-‐server
application.
The
Docker
client
talks
to
the
Docker
server
or
daemon,
which,
in
turn,
does
all
the
work.
Docker
ships
with
a
command
line
client
binary,
‘docker’(“it
is
a
single
binary,
that
can
act
as
both
client
and
server.
As
a
client,
it
passes
request
to
the
Docker
daemon
and
then
process
those
requests
when
they
are
returned.”)
as
well
as
a
full
RESTful
API.
6. Docker
Components
:
Docker
Images
An
image
is
the
build
component
of
a
container.
It
is
a
read-‐only
template
from
which
one
or
more
container
instances
can
be
launched.
Conceptually,
it’s
similar
to
an
AMI.
For
downloading
a
image
from
public
repo,
we
can
use
the
following
command
:
$docker pull ubuntu:12.10
7. 7
Docker
Components
:
Docker
Images
More
about
Docker
Images
:
1. Docker
Images
stored
in
Docker
Hub
or
locally
1. For
Docker
Hub
we
required
Docker
Hub
account
2. Authenticating
Docker
Run
:
sudo docker login
This will create the $HOME/.dockercfg file.
2. We
can
build
our
own
Images
1.docker commit (This method is currently not recommended.)
2. docker build
With
a
Dockerfile
8. 8
Docker
Components
:
Docker
Images
:
Dockerfile
Dockerfile
:
Dockerfile
uses
a
basic
DSL
with
instructions
for
building
Docker
images.
Sample
Dockerfile:
# Version: 0.0.1
FROM ubuntu:14.04
MAINTAINER Abhishek Tomar “abhish.tomar@gmail.com”
RUN apt-get update
RUN apt-get install -y nginx
RUN echo ‘Hi, I am in your container’ > /usr/share/nginx/html/
index.html
EXPOSE 80
9. 9
Docker
Components
:
Docker
Images
:
Dockerfile
Now
Docker
Execung
instrucon
workflow
:
• Docker
runs
a
container
from
the
image.
• An
instrucon
executes
and
makes
a
change
to
the
container.
• Docker
runs
the
equivalent
of
“docker
commit”
to
commit
a
new
layer.
• Docker
then
runs
a
new
container
from
this
new
image.
• The
next
instrucon
in
the
file
is
executed,
and
the
process
repeats
unl
all
instrucons
have
been
executed.
Few
Commands
:
1. For
running
the
docker
with
docker
file
:
$ docker build .
1. Checking
the
history
:
$ docker history <containeranme>
10. 10
Docker
Components
:
Registries
Registries
are
used
to
store
images.
Registries
can
be
local
or
remote.
When
we
launch
a
container,
Docker
first
searches
the
local
registry
for
the
image.
If
it’s
not
found
locally,
then
it
searches
a
public
remote
registry,
called
DockerHub.
If
the
image
is
there,
Docker
downloads
it
to
the
local
registry
and
and
uses
it
to
launch
the
container.
DockerHub
is
similar
to
Github,
in
that
we
can
create
both
public
and
private
image
repositories.
This
makes
it
easy
to
distribute
images
efficiently
and
securely.
“Images live inside the repositories and repository lives on registry.”
11. Docker
Components
:
Containers
Containers
are
not
VM’s
:
Unlike
hypervisor
virtualization,
where
one
or
more
independent
machines
run
virtually
on
physical
hardware
via
an
intermediation
layer,
containers
instead
run
user
space
on
top
of
an
operating
system's
kernel.
They
can
generally
only
run
the
same
or
a
similar
guest
operating
system
as
the
underlying
hosts.
And
a
Docker
Container
is
…
1. An
Image
Format
2. A
Set
of
standard
operations
3. An
execution
environment
13. What
can
you
use
Docker
for?
Some
Small
Use
Cases:
1. I
need
to
see
the
man
page
from
a
specific
version
of
RHEL,
CentOS
or
Fedora
2. I
need
to
quickly
verify
the
command
line
options
of
a
program
3. I
need
to
test
the
functionality
of
a
specific
version
of
software
4. I
need
a
scratch
pad
that
is
NOT
my
system
5. I
need
a
single
daemon
running,
and
I
don’t
care
what
distribution
of
Linux
it
runs
on
(see
registry
below)
14. What
can
you
use
Docker
for?
Some
more
use
Cases
:
1. Making
your
local
development
and
build
workflow
faster.
2. Using
Docker
to
create
isolated
instances
to
run
tests.
3. Building
a
multi-‐user
Platform-‐as-‐a-‐service(PAAS)
infrastructure.
15. 15
Docker
Installation
Requirements:
1. Be
running
a
64-‐bit
architecture
($sudo
uname
-‐a)
2. Kernel
version
3.8
or
later
($sudo
uname
-‐a)
3. Kernel
must
support
an
appropriate
storage
drive
($sudo
grep
‘device-‐mapper’
/proc/
devices)
4. cgroups
and
namespaces
kernel
features
must
be
supported
and
enabled.
5. Check
curl
is
installed
or
not
($which
curl)
16. 16
Docker
Installation
Cont.
#UpdaPng
the
ubuntu
$ sudo apt-get update & apt-get upgrade
#
Installing
latest
version
of
Docker
$ curl -sSL https://get.docker.io/ubuntu/ | sudo sh
#
Check
Whether
Docker
is
running
or
not
$ docker -info
#
Docker
configuraPon
file:
“/etc/default/docker”
By
default
Docker
will
run
on
socket,
if
you
need
to
change
it
to
ip
then
We
will
have
to
change
the
DOCKER_OPTS
variable
in
configuraon
file.
e.g.
DOCKER_OPTS="--host tcp://0.0.0.0:2375 -H unix://var/run/
docker.sock”
17. 1717
Docker
User
Interface
There
are
few
Docker
user
interfaces
and
web
console
available
in
various
states
of
development,
Some
of
the
are
listed
below.
1)
Shipyard
-‐
It
gives
you
the
ability
to
manage
Docker
resources,
including
containers,
images,
hosts,
and
more
from
a
single
management
interface.
2)
DockerUI
-‐
It
is
a
web
interface
that
allows
you
to
a
interact
with
the
Docker
Remote
API.
It’s
written
in
JAVA
Script
using
the
AngularJS
framework.
3)
maDocker
-‐
A
web
UI
written
in
NodeJS
and
Backbone
(in
early
stages
of
development.)
19. 19
1)
Running
a
Nginx
web
server
in
docker
container,
and
Access
it
from
outside.
Dockerfile
:
# Version: 0.0.1
FROM ubuntu:14.04
MAINTAINER Abhishek Tomar
“abhish.tomar@gmail.com”
RUN apt-get update
RUN apt-get install -y nginx
RUN echo ‘Hi, I am in your container’ > /usr/
share/nginx/html/index.html
EXPOSE 80
Demo
&
Understanding
Dockerfile.
20. 20
More
options
in
Docker
file:
1. CMD
:
It’s
similar
to
RUN
instruction
but
rather
than
running
the
command
when
the
container
is
being
built,
it
will
specify
the
command
to
run
when
the
container
is
launched.
For
Example
:
In
docker run
command
:
$sudo run -i -t abhishektomar/webserver /bin/
true
In
Dockerfile:
CMD [“/bin/true”]
2. ENTRYPOINT
:
It’s
similar
to
CMD
but
the
difference
is
CMD
command
instruction
you
can
override
by
docker run
command
but
in
ENTRYPOINT
any
argument
passed
to
docker run
command
will
be
passed
as
argument
to
ENTRYPOINT
Command.
ENTRYPOINT [“/usr/sbin/nginx”]
$sudo run -i -t abhishektomar/webserver -g
“daemonoff;”
Demo
&
Understanding
Dockerfile.
21. 21
3. WORKDIR
:
The
WORKDIR
instruction
set
the
work
directory
for
the
container
and
the
ENTRYPOINT
and/or
CMD
to
be
executed
when
a
container
is
launched
from
an
image.
WORKDIR /opt/tomcat-qa/conf
RUN source vars
WORKDIR /opt/tomcat-qa/bin
ENTRYPOINT startup.sh
4. ENV
:
The
ENV
instruction
is
used
to
set
environment
variables
during
the
image
build
process.
ENV JAVA_HOME /usr/lib/jvm/java-6-sun/bin
RUN service tomcat7 start
5. USER
:
The
USER
specifies
a
user
that
the
image
should
be
run
as;
for
example
:
USER nginx
USER user:group
Demo
&
Understanding
Dockerfile.
22. 22
6. VOLUME
:
The
VOLUME
instruction
adds
volumes
to
any
container
created
from
the
image.
1. Volumes
can
be
shared
and
reused
between
containers.
2. A
container
doesn't
have
to
be
running
to
share
its
volumes.
3. Change
to
a
volume
are
made
directly.
4. Changes
to
a
volume
will
not
be
included
when
you
update
an
image.
5. Volume
persist
until
no
containers
use
them.
Using
VOLUME
instruction
:
VOLUME [“/mnt”] # we can also specify multiple VOLUMES
VOLUME [“/mnt”, “/data”]
7. ADD
:
The
ADD
instruction
adds
files
and
directories
from
our
build
environment
into
our
images;
For
example,
ADD software.lic /opt/application/software.lic
In
the
above
example, ADD
instruction
will
copy
the
file
software.lic
from
the
build
directory
to /opt/application/
software.lic in
the
image.
Demo
&
Understanding
Dockerfile.
23. 23
8. COPY
:
The
COPY
instruction
is
closely
related
to
the
ADD
instruction.
The
key
difference
is
that
the
COPY
instruction
is
purely
focused
on
copying
local
files
from
the
build
context
and
does
not
have
an
extraction
or
decompression
capabilities.
COPY cont.d /etc/apache2/
9. ONBUILD
:
The
ONBUILD
instruction
adds
triggers
to
images.
A
trigger
is
executed
when
the
image
is
used
as
the
basis
of
another
image.
Demo
&
Understanding
Dockerfile.
26. 26
1.
You
can
only
specify
CMD
instrucon
once
in
the
Docker
files,
if
mulple
specified
last
one
is
used.
2.
If
required
at
runme,
you
can
override
the
ENTRYPOINT
instrucon
using
the
docker
run
command
with
—ENTRYPOINT
flag.
3.
You
can
override
the
working
directory
at
runme
with
the
-‐w
flag.
4.
For
override
docker
env
you
can
use
-‐e
flag.
5.
At
runme
you
can
use
-‐u
flag
to
override
the
user,
if
you
are
not
specifying
any
user
than
default
user
would
be
root.
6.
ADD
:
has
some
special
magic
for
taking
care
of
local
tar
archive
is
specified
as
the
source
file,
the
Docker
will
automacally
unpack
it
for
you:
ADD
lateste.tar.gz
/opt/latest/
7.
COPY
:
The
source
of
the
files
must
be
the
path
to
a
file
or
directory
relave
to
the
build
context,
the
local
source
directory
in
which
your
Dockerfile
resides.
Dockerfile
Tips
:
27. 27
4.
We
will
be
creating
a
infrastructure
and
hosting
a
Wordpress
site
on
Docker.
—
Create
A
MySQL
Docker
Instance
—
Create
A
Web
Server
Docker
Instance
Demo