latcraft | docker 101

49
01

Upload: aestas-it

Post on 09-Jan-2017

420 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: LatCraft | Docker 101

01

Page 2: LatCraft | Docker 101

Let's start!02

Page 3: LatCraft | Docker 101

What's in this workshopStarting up Docker Machine

Docker history, components, commands

Excercises

More excercises

••••

03

Page 4: LatCraft | Docker 101

Practical!04

Page 5: LatCraft | Docker 101

PreparationWe need a VM with Docker inside. Instructions are here:

http://bit.ly/LATCRAFT_DOCKER

Let's share the code in the Gist as well!

05

Page 6: LatCraft | Docker 101

Docker facts3 years old already

32K+ stars on GitHub

100K+ dockerized applications on Docker Hub

425M+ Docker Engine downloads

180+ Docker meetup groups in 50+ countries

1400+ community contributors

50K projects on GitHub using Docker

•••••••

06

Page 7: LatCraft | Docker 101

What is Docker?Virtualization tool like VirtualBox?

Virtual machine manager like Vagrant?

Configuration management tool like Chef or Puppet?

cgroups ,  libvirt , LXC?

••••

07

Page 8: LatCraft | Docker 101

DockerOpen source engine to commoditize LXC (containers)

Container virtualization

Build, pack, ship and run applications as containers

Build once, run in many places

Isolated and content agnostic

•••••

08

Page 9: LatCraft | Docker 101

Linux containersAvailable in modern kernels since 2008

Generically isolates resource usage (CPU, memory, disk, network)

Guarantees resources to application(s)

Can be adjusted on the fly

••••

09

Page 10: LatCraft | Docker 101

Kernel namespacesIsolating views of the system

Can make a process think it's the only process

Built­in way to "virtualize" processes

•••

10

Page 11: LatCraft | Docker 101

Kernel namespacesmnt  (mount points, filesystem)

pid  (processes)

net  (network stack)

ipc  (inter­process communication)

uts  (hostname)

user  (UIDs)

••••••

11

Page 12: LatCraft | Docker 101

Inside the container (application)my code

my libraries

my package manager

my app

my data

•••••

12

Page 13: LatCraft | Docker 101

Outside the container (operations)shared data

logging

remote access

network configuration

monitoring

•••••

13

Page 14: LatCraft | Docker 101

Container performanceProccesses are isolated, but run directly on the host

CPU ­ native performance

Memory ­ small footprint required

Network ­ small overhead

••••

14

Page 15: LatCraft | Docker 101

Containers vs. VMs

15

Page 16: LatCraft | Docker 101

Containers vs. VMs

16

Page 17: LatCraft | Docker 101

Dockerconcepts

17

Page 18: LatCraft | Docker 101

Docker engineDocker is a simple client/server application

A Docker Client talks to Docker daemon, which executes the work

Docker Daemon also exposes RESTFul API, that can be used

remotely

•••

18

Page 19: LatCraft | Docker 101

Docker imagesRead­only templates from which containers are launched

Each image consists of series of layers using union file system

When image gets modified a new layer is created

Docker can also use additional file systems

••••

19

Page 20: LatCraft | Docker 101

Docker images

20

Page 21: LatCraft | Docker 101

Docker imagesDocker images can be shared

Standard templates for starting containers

Reproducible way to easily build trusted images

•••

21

Page 22: LatCraft | Docker 101

Docker containerSingle process running within environment created from Docker Image“22

Page 23: LatCraft | Docker 101

Docker registryA repository of Docker images

Registry can be private or public

Docker Hub is a public Docker registry

•••

23

Page 24: LatCraft | Docker 101

Dockerfile

24

Page 25: LatCraft | Docker 101

Dockercommands25

Page 26: LatCraft | Docker 101

docker pullPull image from remote registry (or Docker Hub) into local cache of

Docker images on current Docker Host:

docker pull busybox01.

26

Page 27: LatCraft | Docker 101

docker imagesList images cached on current Docker Host:

docker images01.

27

Page 28: LatCraft | Docker 101

docker buildBuild Docker Image from Dockerfile located in the current directory:

docker build ‐t=myimage:1.0 .01.

28

Page 29: LatCraft | Docker 101

docker rmiRemove image from local cache:

docker rmi <image_id>01.

29

Page 30: LatCraft | Docker 101

docker runStart container from Docker image:

docker run busybox echo "hello world"01.

30

Page 31: LatCraft | Docker 101

docker psList currently running container:

docker ps01.

31

Page 32: LatCraft | Docker 101

docker stop|kill(Forcedly) Stop running container:

docker kill <container_id>01.

32

Page 33: LatCraft | Docker 101

docker rmRemove stopped container:

docker rm <container_id>01.

33

Page 34: LatCraft | Docker 101

Task 01 (start Docker container fromexisting image)Get image from Docker Registry e.g.  docker pull jenkins

List available images with  docker images  command.

Start your first container  docker run jenkins  command.

Press  Ctrl+C  to kill container.

Check that it's not running with  docker ps  command.

Run container in detached mode by passing  ‐d  option.

Expose port to access container from your host using  ‐p  option.

•••••••

34

Page 35: LatCraft | Docker 101

Task 02 (build an image from existingDockerfile)Get  aaconvert  project from GitHub: 

https://github.com/mafr/docker‐aaconvert.git

From project's directory run: 

docker build ‐t aaconvert .

Start throw­away container to convert an image into ASCII art: 

docker run ‐‐rm aaconvert  

https://www.google.com/favicon.ico > docker.txt

35

Page 36: LatCraft | Docker 101

Task 03 (build your own Docker image)Create  Dockerfile  to build PetClinic application.

Application code is here: 

https://github.com/spring­projects/spring­petclinic.

Build Docker image with the help of: 

docker build ‐‐tag=petclinic:1.0 .

Verify image is listed with  docker images .

••

36

Page 37: LatCraft | Docker 101

Task 03 (build your own Docker image)Hint: command to build application is: 

mvnw ‐e clean install tomcat7:help ‐DskipTests

Hint: command to run application is: 

mvnw ‐e tomcat7:run ‐DskipTests

37

Page 38: LatCraft | Docker 101

Task 04 (start Docker container fromyour image)Start container(s) with  docker run petclinic:1.0  command.

Access container's process through its port ( 9966 ).

Kill container(s) with  docker kill .

Remove container(s) with  docker rm .

Remove image(s) with  docker rmi .

•••••

38

Page 39: LatCraft | Docker 101

Task 05 (start Docker environment withmultiple containers)Start MySQL server inside container: 

docker run  

‐e MYSQL_ROOT_PASSWORD=petclinic  

‐e MYSQL_DATABASE=petclinic  

‐p 3306:3306 mysql:5.7.8

Rebuild PetClinic image to use MySQL database (change  pom.xml ).

Start PetClinic container using data from MySQL container.

••

39

Page 40: LatCraft | Docker 101

Task 06 (use remote Docker Engine)Configure  DOCKER_HOST  environment variable to use

NNN.NNN.NNN.NNN:2375 .

Build images with unique  ‐‐tag  option to not conflict with other

students.

Start containers on the remote host by exposing unique ports with  ‐p

(available range is  8081‐8099 ) and naming containers with  ‐‐name .

Play with  docker ps  and  ‐‐filter  to identify and kill only your

containers.

40

Page 41: LatCraft | Docker 101

Conclusion41

Page 42: LatCraft | Docker 101

Linkshttps://www.docker.com/products/docker­toolbox

https://github.com/wsargent/docker­cheat­sheet

https://www.mindmeister.com/389671722/open­container­ecosystem­

formerly­docker­ecosystem

•••

42

Page 43: LatCraft | Docker 101

Book: Docker up and running

43

Page 44: LatCraft | Docker 101

UpcomingEvents

44

Page 45: LatCraft | Docker 101

45

Page 46: LatCraft | Docker 101

46

Page 47: LatCraft | Docker 101

Training: DevOps MasterClass / ExtremeAutomation8­9 September, 2016

This 2­day workshop focuses on solving challenges that organisations

face when implementing DevOps initiatives. It introduces principles of

DevOps and tools that help reach full automation of infrastructure

provisioning and software delivery. Theoretical background as well as

practical hands­on examples of tools like Vagrant, Docker, AWS and

others are given during this workshop.

“47

Page 48: LatCraft | Docker 101

Training: Effective Coding Principles andPatterns in Java 814­15 September, 2016

During this intensive, practical and entertaining 2­day course you will

learn principles, practices and patterns for writing readable,

maintainable and effective code.“48

Page 49: LatCraft | Docker 101

Thank you!49