Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Get Dockerized in 90 minutes

No description
by

Sah Lee

on 1 June 2016

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Get Dockerized in 90 minutes

$
docker run -ti learn/tutorial bash
root@66afdd3160ce:/#
useradd johndoe
root@66afdd3160ce:/#

grep johndoe /etc/shadow
johndoe:!:16444:0:99999:7:::
root@66afdd3160ce:/#

exit
$ docker ps –lq
e1c901d86481
$ docker commit `docker ps -lq` johnsimage
c8c32cd4bdd71a2cb4d593ba16db86a74c9b4b32ae488101377c1dd5c1bfd564
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
johnsimage latest c8c32cd4bdd7 29 seconds ago 128.4 MB
learn/tutorial latest 8dbd9e392a96 21 months ago 128 MB
$ docker run johnsimage grep johndoe /etc/shadow
root@42510ec97b30:/#

grep johndoe /etc/shadow
johndoe:!:16444:0:99999:7:::
$ docker run -ti -u johndoe johnsimage bash
johndoe@b5974c3ba4da:/$

The Linux container engine
Pack, ship and run applications as lightweight containers

VM-like end user experience
Exercise 1
Objectives

Run a command inside a container
Interact with a container
Exercise 4
Objectives

Understand the network
Publish a service
Get Dockerized in 90 minutes
Better than VMs
$ echo "Hello World"
Hello World
$ docker run
learn/tutorial /bin/
echo "Hello World"
Unable to find image 'learn/tutorial' locally
Pulling repository learn/tutorial
8dbd9e392a96: Download complete
Hello World
$ docker run
learn/tutorial /bin/
echo "Hello World"
Hello World
$ docker run -i -t
learn/tutorial
/bin/bash
root@bb25409fde0d:/#
echo "Hello World"
Hello World
root@bb25409fde0d:/#
exit
$
First Docker container
Exercise 2
Objectives

Install an application in a container
Create a new image from a container
Create your own image
Avaiable online:
https://www.docker.com/tryit/
Images & layers
The rootfs is mounted read-only

A read-write file system is then added over the read-only file system (union mount)
There may be multiple read-only file systems stacked on top of each other.

We think of each one of these file systems as a
layer
.
Layers
Read more:
https://docs.docker.com/terms/layer/
Objectives

Dig deeper in layers
$ docker images -tree
Warning: '-tree' is deprecated, it will be removed soon. See usage.
└─8dbd9e392a96 Virtual Size: 128 MB Tags: learn/tutorial:latest
└─c8c32cd4bdd7 Virtual Size: 128.4 MB Tags: johnsimage:latest
$ docker images --no-trunc -q
johnsimage
c8c32cd4bdd71a2cb4d593ba16db86a74c9b4b32ae488101377c1dd5c1bfd564
$ find /var/lib/docker/aufs/diff/`docker images --no-trunc -q
johnsimage`
/etc/
/var/lib/docker/aufs/diff/c8c32cd4bdd71a2cb4d593ba16db86a74c9b4b32ae488101377c1dd5c1bfd564/etc/
/var/lib/docker/aufs/diff/c8c32cd4bdd71a2cb4d593ba16db86a74c9b4b32ae488101377c1dd5c1bfd564/etc/passwd-
/var/lib/docker/aufs/diff/c8c32cd4bdd71a2cb4d593ba16db86a74c9b4b32ae488101377c1dd5c1bfd564/etc/gshadow
/var/lib/docker/aufs/diff/c8c32cd4bdd71a2cb4d593ba16db86a74c9b4b32ae488101377c1dd5c1bfd564/etc/shadow-
/var/lib/docker/aufs/diff/c8c32cd4bdd71a2cb4d593ba16db86a74c9b4b32ae488101377c1dd5c1bfd564/etc/group
/var/lib/docker/aufs/diff/c8c32cd4bdd71a2cb4d593ba16db86a74c9b4b32ae488101377c1dd5c1bfd564/etc/gshadow-
/var/lib/docker/aufs/diff/c8c32cd4bdd71a2cb4d593ba16db86a74c9b4b32ae488101377c1dd5c1bfd564/etc/shadow
/var/lib/docker/aufs/diff/c8c32cd4bdd71a2cb4d593ba16db86a74c9b4b32ae488101377c1dd5c1bfd564/etc/passwd
/var/lib/docker/aufs/diff/c8c32cd4bdd71a2cb4d593ba16db86a74c9b4b32ae488101377c1dd5c1bfd564/etc/group-
Read more:
http://blog.thoward37.me/articles/where-are-docker-images-stored/
A peek inside the layers
Exercise 3
A read-only Layer is called an
image
.

An image never changes.
Images
Read more:
https://docs.docker.com/terms/image/
Network
Invisible from outside the container
Ports are exposed with NAT
Run a service in a container
$ docker run --rm -ti learn/tutorial bash
root@bcc917642a0c:/#

apt-get install -y apache2 curl
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
root@bcc917642a0c:/#

curl localhost:80
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
root@bcc917642a0c:/#
$ curl localhost:80
curl: (7) Failed to connect to localhost port 80: Connection refused
TERMINAL A
TERMINAL B
$ docker run
--publish
8080:80 -ti learn/tutorial bash
root@b2c93f1abdec:/#

apt-get install -y apache2 curl
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
root@b2c93f1abdec:/#

curl localhost:80
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
root@b2c93f1abdec:/#
$ curl localhost:80
curl: (7) Failed to connect to localhost port 80: Connection refused
$ curl localhost:8080
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
$
TERMINAL A'
TERMINAL B'
Read more:
http://pierre-jean.baraud.fr/blog/2014/06/02/host-docker-containers/
More tips
$ docker run -d|--detach ...
# Detached mode
$ docker run -i|--interactive ...
# Keep stdin open
$ docker run -t|--tty ...
# Allocate a pseudo-tty
$ docker run -p|--publish HPORT:PORT ...
# Keep stdin open
$ docker run --name="FOOBAR" ...
# Name the container
Key combination "Ctrl-P + Ctrl-Q" detaches you from a container

"docker attach CONTAINER" attaches you to a running container
Exercise 5
$ docker run -d learn/tutorial bash -c "while true; do echo There is no spoon; sleep 1; done"
218c9d93eb73521eea5aa33aae1fb1f876f288fd90f85a85ba886be47172a6f9
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
218c9d93eb73 learn/tutorial:latest "bash -c 'while true 7 seconds ago Up 5 seconds silly_goodall
$ docker logs -f `docker ps -lq`
There is no spoon
There is no spoon
There is no spoon
There is no spoon
...
$ docker stop `docker ps -lq`
218c9d93eb73
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$
First Dockerized daemon
Objectives

Run a container in detached mode
Follow the STDOUT of a detached container
docker
/ˈdɒkər/

noun
1. a laborer on shipping docks; longshoreman.
Read more:
http://dictionary.reference.com/browse/docker
It's about containers
Docker is not about docks
read more:
http://blog.trifork.com/2013/08/08/next-step-in-virtualization-docker-lightweight-containers/
Inspired by "Learn Docker in 90 minutes" (Larry Cai)
Credits
This Prezi is inspired by Larry Cai's "Learn Docker in 90 minutes"



Copyright of pictures and some contents, if applicable, belongs to the original author.
http://www.slideshare.net/larrycai/learn-docker-in-90-minutes
Dockerfile
$ cat /tmp/Dockerfile
FROM learn/tutorial:latest
MAINTAINER Sah Lee <contact@leesah.name>
RUN apt-get install -y ping
$ docker build -t ping /tmp/
Sending build context to Docker daemon 2.455 MB
Sending build context to Docker daemon
Step 0 : FROM learn/tutorial:latest
---> 8dbd9e392a96
Step 1 : MAINTAINER Sah Lee <contact@leesah.name>
---> Running in 3fe58915b7ff
---> fb0e98637044
...
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ping latest 6ef3b4cf5171 34 seconds ago 139.5 MB
learn/tutorial latest 8dbd9e392a96 21 months ago 128 MB
...
$
Have Docker build images for you
Exercise 6
Objectives

Write a Dockerfile
Build an image from a Dockerfile
FROM

image:tag

- defines base image
MAINTAINER

name

- sets author information
RUN

command

- runs arbitrary command
CMD

command param1 param2

- defines default command to run
ENV

key value

- sets environment variable
ADD

src... dest

- adds local file
COPY

src... dest
ENTRYPOINT

command param1 param2
VOLUME

["/data"]
EXPOSE

port
USER
username
WORKDIR
/path/to/workdir
ONBUILD
[INSTRUCTION]
A text document with step-by-step instructions on building an image

Following the instructions, Docker builds your image automatically
More Dockerfile instructions
Designed for sharing
Repositories
: the place where you can search, pull, or share Docker images
ubuntu
learn/tutorial
leesah/gitlab-ce
...

Docker Hub
: a centralized resource for working with Docker and its components

Official repositories
: certified repositories from vendors and contributors to Docker
Exercise 7
Objectives

Register an account on Docker Hub
Create an Automated Build with a GitHub project
More fun with Docker
Composing a complete service with multiple containers

Sharing file system among containers

Network among containers

Interacting with host from within containers

Using supervisor

...
wait..., what's the point of all this if running inside a container doesn't make any difference
Isolated runtime environment
$ docker run learn/tutorial /bin/hostname
86db9cec14fe
$ docker run learn/tutorial
/bin/
hostname
7adab01c8bfd
$ docker run learn/tutorial /bin/ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
18: eth0: <NO-CARRIER,BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 22:83:c3:2e:6d:d4 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.8/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::2083:c3ff:fe2e:6dd4/64 scope link tentative
valid_lft forever preferred_lft forever
$
$
docker search

TERM

# Search the Docker Hub for images
$
docker pull

NAME[:TAG]

# Pull an image from the registry
$
docker images

# List local images
$
docker rmi

IMAGE

# Remove images

$
docker run

IMAGE [COMMAND]

# Run a command in a new container
$
docker ps

# List active containers
$
docker start|stop|rm

CONTAINER

# Start/stop/remove containers

$
docker build

# Build image from a Dockerfile
Frequently used commands
Full transcript