LatCraft | Docker 101

Post on 09-Jan-2017

420 views 0 download

Transcript of LatCraft | Docker 101

01

Let's start!02

What's in this workshopStarting up Docker Machine

Docker history, components, commands

Excercises

More excercises

••••

03

Practical!04

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

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

What is Docker?Virtualization tool like VirtualBox?

Virtual machine manager like Vagrant?

Configuration management tool like Chef or Puppet?

cgroups ,  libvirt , LXC?

••••

07

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

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

Kernel namespacesIsolating views of the system

Can make a process think it's the only process

Built­in way to "virtualize" processes

•••

10

Kernel namespacesmnt  (mount points, filesystem)

pid  (processes)

net  (network stack)

ipc  (inter­process communication)

uts  (hostname)

user  (UIDs)

••••••

11

Inside the container (application)my code

my libraries

my package manager

my app

my data

•••••

12

Outside the container (operations)shared data

logging

remote access

network configuration

monitoring

•••••

13

Container performanceProccesses are isolated, but run directly on the host

CPU ­ native performance

Memory ­ small footprint required

Network ­ small overhead

••••

14

Containers vs. VMs

15

Containers vs. VMs

16

Dockerconcepts

17

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

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

Docker images

20

Docker imagesDocker images can be shared

Standard templates for starting containers

Reproducible way to easily build trusted images

•••

21

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

Docker registryA repository of Docker images

Registry can be private or public

Docker Hub is a public Docker registry

•••

23

Dockerfile

24

Dockercommands25

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

Docker images on current Docker Host:

docker pull busybox01.

26

docker imagesList images cached on current Docker Host:

docker images01.

27

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

docker build ‐t=myimage:1.0 .01.

28

docker rmiRemove image from local cache:

docker rmi <image_id>01.

29

docker runStart container from Docker image:

docker run busybox echo "hello world"01.

30

docker psList currently running container:

docker ps01.

31

docker stop|kill(Forcedly) Stop running container:

docker kill <container_id>01.

32

docker rmRemove stopped container:

docker rm <container_id>01.

33

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

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

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

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

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

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

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

Conclusion41

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

Book: Docker up and running

43

UpcomingEvents

44

45

46

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

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

Thank you!49