reveal.js - the html presentation framework · 2016-06-12 · docker, tutorial 0

45
Intro to Docker Intro to Docker Container technology so easy it should be illegal not to use it. Linux User Group of Davis (LUGOD) 05/16/2016 0 reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i... 1 of 45 6/11/16, 7:16 PM

Upload: others

Post on 17-Feb-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Intro to DockerIntro to DockerContainer technology so easy it should be

illegal not to use it.Linux User Group of Davis (LUGOD)

05/16/2016

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

1 of 45 6/11/16, 7:16 PM

Page 2: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

OutlineOutlineSlides available at Why Docker?What is Docker?Basic docker terminologies and commandsHands-on exercise:

build a Docker imagerun Docker container to update theHackerWithinDavis chapter website

http://goo.gl/cj70Fw

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

2 of 45 6/11/16, 7:16 PM

Page 3: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Why Docker?Why Docker?

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

3 of 45 6/11/16, 7:16 PM

Page 4: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Why Docker?Why Docker?Helps reproduce an exact software environmentGood for:

software development / deploymentreproducible science!teaching (and grading)

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

4 of 45 6/11/16, 7:16 PM

Page 5: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

What is Docker?What is Docker?An open-source technology thatallows you to package an appwith all its dependencies into astandardized unit for software

development.

-Docker website

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

5 of 45 6/11/16, 7:16 PM

Page 6: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

What is Docker?What is Docker?One container for running approximately one app

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

6 of 45 6/11/16, 7:16 PM

Page 7: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Virtual machines (left) vsVirtual machines (left) vsDocker (right)Docker (right)

Software container = operating-system-levelvirtualization

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

7 of 45 6/11/16, 7:16 PM

Page 8: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Virtual machines (left) vsVirtual machines (left) vsDocker (right)Docker (right)

VM has more overhead

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

8 of 45 6/11/16, 7:16 PM

Page 9: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

What is Docker?What is Docker?Containers start up faster (~500 ms)

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

9 of 45 6/11/16, 7:16 PM

Page 10: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Basic Docker terminologiesBasic Docker terminologies

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

10 of 45 6/11/16, 7:16 PM

Page 11: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

DockerhubDockerhuban where you can pull and

host publicly available Docker imagesonline registry

$ docker pull karenyng/hackerwithin_dockerfile

searches Dockerhub for an image file

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

11 of 45 6/11/16, 7:16 PM

Page 12: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Docker imageDocker image

Fig. Docker infrastructure if host machine is Linux. (fig stolen from Docker)

static image that packages Linux system runtime /library files along with the softwarecan have parent / base imageimmutable

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

12 of 45 6/11/16, 7:16 PM

Page 13: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

ContainerContainer

a running / stopped instance of an image

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

13 of 45 6/11/16, 7:16 PM

Page 14: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

DockerfileDockerfilea recipe for building a Docker imagecan contain runtime configurations

vs the a Dockerfile example original installation guide

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

14 of 45 6/11/16, 7:16 PM

Page 15: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Hands-on sessionHands-on session

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

15 of 45 6/11/16, 7:16 PM

Page 16: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Start Docker daemonStart Docker daemonLinux users execute:

$ sudo docker -d &

Instructions for using Docker without sudo.here

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

16 of 45 6/11/16, 7:16 PM

Page 17: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Other caveats: 64-bit LinuxOther caveats: 64-bit Linuxneededneeded

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

17 of 45 6/11/16, 7:16 PM

Page 18: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Alternative instruction forAlternative instruction forMac and Windows UserMac and Windows User

Start Docker QuickStart terminal

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

18 of 45 6/11/16, 7:16 PM

Page 19: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Ex1: Building the image fromEx1: Building the image froma a DockerfileDockerfile

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

19 of 45 6/11/16, 7:16 PM

Page 20: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Ex1: Building the image fromEx1: Building the image froma a DockerfileDockerfile

$ git clone \https://github.com/karenyyng/hackerwithin_dockerfile$ cd hackerwithin_dockerfile$ vim Dockerfile

Dockerfile ref API

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

20 of 45 6/11/16, 7:16 PM

Page 21: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

How did I build and debugHow did I build and debugthe image?the image?

switch to a problematic dockerfile first...$ git fetch origin # fetch all remote branches$ git checkout -b failed origin/failed$ docker build -t karenyng/silly .

where -t tags the image withREPO_NAME/IMAGE_NAME.

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

21 of 45 6/11/16, 7:16 PM

Page 22: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Debug problematic image byDebug problematic image byrunning the image beforerunning the image before

problem occursproblem occursGet the CACHED IMAGE HASH from printed

message.$ docker run -ti <CACHED IMAGE HASH>

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

22 of 45 6/11/16, 7:16 PM

Page 23: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Build image then check whatBuild image then check whatimages are locally availableimages are locally available

$ docker build -t MY_DOCKERHUB_REPONAME/silly .$ docker images

-t tags the REPO/IMAGE_NAME

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

23 of 45 6/11/16, 7:16 PM

Page 24: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Login and push image toLogin and push image toDockerHubDockerHub

$ docker login $ docker push MY_DOCKERHUB_REPONAME/silly

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

24 of 45 6/11/16, 7:16 PM

Page 25: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Or commit Dockerfile toOr commit Dockerfile toGitHub for an automatedGitHub for an automatedbuild of Docker image onbuild of Docker image on

DockerHubDockerHub

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

25 of 45 6/11/16, 7:16 PM

Page 26: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Check what containers areCheck what containers arerunningrunning

# only shows running containers $ docker ps

# shows all the containers $ docker ps -a

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

26 of 45 6/11/16, 7:16 PM

Page 27: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Saving the container as anSaving the container as animage on local machineimage on local machine

$ docker commit --help$ docker commit CONTAINER_ID DOCKERHUB_REPO/IMAGE_NAME

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

27 of 45 6/11/16, 7:16 PM

Page 28: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Ex2: Running the Jekyll webEx2: Running the Jekyll webblogblog

keep Jekyll Hackerwithin website files (html /markdown) outside containerbuilt all software dependencies ( , ) inside

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

28 of 45 6/11/16, 7:16 PM

Page 29: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Ex2: Running the Jekyll webEx2: Running the Jekyll webblogblog

$ git clone \https://github.com/thehackerwithin/davis$ cd davis

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

29 of 45 6/11/16, 7:16 PM

Page 30: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Running the Jekyll web blogRunning the Jekyll web blog$ docker run -it \-p 4000:4000 \ -v $PATH_TO_HACKERWITHIN_DAVIS_DIR:/root \karenyng/hackerwithin_dockerfile \ruby -S jekyll serve \--host=0.0.0.0 --watch --force_polling

Now it is up and running!

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

30 of 45 6/11/16, 7:16 PM

Page 31: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Check the IP address of yourCheck the IP address of yourDocker machineDocker machine

$ docker-machine ip 127.0.0.1 # for Linux192.168.99.100 # for Mac and Windows

Now point your browser to DOCKER_IP:4000

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

31 of 45 6/11/16, 7:16 PM

Page 32: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

What did we just do?What did we just do?$ docker run -it \-p 4000:4000 \ -v $PATH_TO_HACKERWITHIN_DAVIS_DIR:/root \karenyng/hackerwithin_dockerfile \ruby -S jekyll serve \--host=0.0.0.0 --watch --force_polling

docker run runs a certain image, in this casekarenyng/hackerwithin_dockerfile which wehave pulled previously

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

32 of 45 6/11/16, 7:16 PM

Page 33: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

What did we just do?What did we just do?$ docker run -it \-p 4000:4000 \ -v $PATH_TO_HACKERWITHIN_DAVIS_DIR:/root \karenyng/hackerwithin_dockerfile \ruby -S jekyll serve \--host=0.0.0.0 --watch --force_polling

-i means run iteractively, asking the container to readfrom the host's STDIN-t asks container to bind to a pseudo-terminal

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

33 of 45 6/11/16, 7:16 PM

Page 34: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

What did we just do?What did we just do?$ docker run -it \-p 4000:4000 \ -v $PATH_TO_HACKERWITHIN_DAVIS_DIR:/root \karenyng/hackerwithin_dockerfile \ruby -S jekyll serve \--host=0.0.0.0 --watch --force_polling

-p HOST_PORT:CONTAINER_PORT exposes the port

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

34 of 45 6/11/16, 7:16 PM

Page 35: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

What did we just do?What did we just do?$ docker run -it \-p 4000:4000 \ -v $PATH_TO_HACKERWITHIN_DAVIS_DIR:/root \karenyng/hackerwithin_dockerfile \ruby -S jekyll serve \--host=0.0.0.0 --watch --force_polling

-v $PATH_TO_HACKERWITHIN_DAVIS_DIR:/roottells Docker to mount the directory of theHackerwithin Davis repo to /root in the

container

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

35 of 45 6/11/16, 7:16 PM

Page 36: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

What did we just do?What did we just do?$ docker run -it \-p 4000:4000 \ -v $PATH_TO_HACKERWITHIN_DAVIS_DIR:/root \karenyng/hackerwithin_dockerfile \ruby -S jekyll serve \--host=0.0.0.0 --watch --force_polling

Last two lines tell Jekyll to keep onmonitoring for changes.

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

36 of 45 6/11/16, 7:16 PM

Page 37: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Clearing up spaceClearing up space$ docker stop CONTAINER_ID $ docker ps -a # checks local containers $ docker rm CONTAINER_ID # removes container $ docker images # checks local images$ docker rmi IMAGE_NAME # removes image

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

37 of 45 6/11/16, 7:16 PM

Page 38: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

What is next? Use Docker forWhat is next? Use Docker for......

running SaaS for a startuprunning a continuous integration servicerunning R Studio ( ) or webclient for remote machines

NERSC HPC version Jupyter

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

38 of 45 6/11/16, 7:16 PM

Page 39: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Learning resourcesLearning resources

San Francisco

How to use from Docker

Docker tutorialDocker online webminars

Docker meetupsDocker best practises

Jekyll

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

39 of 45 6/11/16, 7:16 PM

Page 40: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Thanks for listening!Thanks for listening!

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

40 of 45 6/11/16, 7:16 PM

Page 41: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Linux resourcesLinux resources for running Docker on Linux without

sudo privileges.Guide

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

41 of 45 6/11/16, 7:16 PM

Page 42: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Hands-on exercises for thoseHands-on exercises for thosewho want to run docker im-who want to run docker im-

agesagesdifficulty: easy

run and modify the HackerWithinrun run Jupyter for Spark/ SparkR/PySpark / Scipy Jupyter notebook in Dockerrun

pagerOpenSci R studio web client

Docker-stack

Tensorflow

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

42 of 45 6/11/16, 7:16 PM

Page 43: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Building Dockerfiles / usingBuilding Dockerfiles / usingDocker on the CloudDocker on the Cloud

difficulty: more involvedwrite your own Dockerfile and build your own appuse Docker compose to run the Docker 3rdbirthday web app setup the HortonWorks Data Platformfor playing with Hadoop and Spark in Dockerchallenge: write the Dockerfile(s) for Astrophysicscodes, e.g.

,

tutorialsandbox

CosmosisAstrometry.net

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

43 of 45 6/11/16, 7:16 PM

Page 44: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Incomplete collection of use-Incomplete collection of use-ful commandsful commands

Restart stopped container$ docker start CONTAINER_ID $ docker attach CONTAINER_ID

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

44 of 45 6/11/16, 7:16 PM

Page 45: reveal.js - The HTML Presentation Framework · 2016-06-12 · Docker, tutorial 0

Incomplete collection of use-Incomplete collection of use-ful commandsful commands

If your container is running in backgroundand you want to use the command prompt

inside the container$ docker exec -it $(docker ps -q) bash

0

reveal.js - The HTML Presentation Framework http://127.0.0.1:8000/dockerTutorial_LUGOD.html?print-pdf#/i...

45 of 45 6/11/16, 7:16 PM