46
UBC LAUNCH PAD A DEVELOPER’S GUIDE TO DOCKER WORKSHOP BRUNO BACHMANN, ROBERT LIN

A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

  • Upload
    others

  • View
    23

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

UBC LAUNCH PAD

A DEVELOPER’S GUIDE TO DOCKER

WORKSHOP

BRUNO BACHMANN, ROBERT LIN

Page 2: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

slides.ubclaunchpad.com/workshops/guide-to-docker.pdf

Slides!

Page 3: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

docs.docker.com/install/#supported-platforms

Install Docker!

Page 4: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Why Containers

You’re building a basic web app...

APP DATABASE

Page 5: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

You’re providing a service...

Why Containers

Page 6: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

You’re providing a service...

Microservice A

Microservice B

Microservice C

Why Containers

Page 7: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

You’re providing a service to millions of users...

Microservice A

Microservice B

Microservice C

Why Containers

Page 8: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Microservice A

Microservice B

Microservice C

Microservice A

Microservice B

Why Containers

Scale the service up to match demand

Page 9: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Microservice A

Microservice B

Microservice C

Microservice A

Microservice B

Why Containers

Scale the service up to match demand

Page 10: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Scale the service down as needed

Microservice A

Microservice B

Why Containers

Scale back up tomorrow

Page 11: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Solution

What if you could encapsulate your

apps within portable boxes?

What if these boxes could contain

everything your program needs?

What if this box could run your

program no matter where you put

the box?

?

Page 12: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Solution

You could call these boxes…

CONTAINERS

Code

Libraries

Folders

Logos

Configuration

Page 13: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Q & A

Page 14: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Containerization

Technical Overview

Page 15: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Containerization

www.docker.com/resources/what-container

Technical Overview

Page 16: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Building Blocks

layered description of

the file system

Ubuntu

Python

simple-app

sets of processes with isolated

views of the system

Other Processes

File System

Network

IMAGES CONTAINERS

Page 17: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Docker Architecture

docs.docker.com/engine/docker-overview/#docker-architecture

Page 18: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Docker Architecture

Networking

HOST

Docker Daemon

Google Chrome

...

Docker Network

Internet

Page 19: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Docker Architecture

Volumes

HOST

opt

/

my-app

...

Docker Network

Page 20: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Docker in the Wild

130,000,000+

SUBSCRIBERS

140,000,000+

HOURS WATCHED

PER DAY

www.statista.com/topics/842/netflix

media.netflix.com/en/press-releases/2017-on-netflix-a-year-in-bingeing

Page 21: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Docker in the Wild

7

REGIONAL DEPLOYMENTS

3,000,000+

CONTAINERS LAUNCHED

PER WEEK

10,000+

EC2 VIRTUAL MACHINES

medium.com/netflix-techblog/titus-the-netflix-container-management-platform-is-now-open-source-f868c9fb5436

Page 22: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Docker in the Wild

back-end services

Page 23: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Q & A

Page 24: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

DIY!

github.com/ubclaunchpad/workshop-guide-to-docker

Repository

Page 25: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

demo.Dockerfile

Dockerfiles are used to define

and build Docker images

Each step is a command that

makes up a “layer”

Page 26: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

1 Make sure Docker is running

2 Build the example image:

3 Start a container from your

image:

Getting Started

Page 27: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Getting Started

Visit the server that the container starts: http://localhost:8000/

Page 28: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

What did we do?

“build an image using demo.Dockerfile”

“Hey Docker!” “call this image ‘my-app’”

Page 29: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

What did we do?

“create and run a container in

interactive mode and remove it afterwards”

“Hey Docker!” “create this container using the ‘my-app’ image”

“I want to access this container’s port 8000 on

my computer’s port 8000”

Page 30: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

this command is run when the container starts

What did we do?

Page 31: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

DIY!

start with an image that has Node.js

add an “entrypoint” command to install dependencies and run the website inside a Docker container

leverage volume mounting to allow code changes to be reflected instantly in a container

Activity: Docker for Development

Page 32: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

to install dependencies and run the web app on port 3000:

Useful Tidbitscreating a directory and

setting path in image:

building an image:

exposing ports and mounting

directories:

Page 33: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

DIY!

build your new image and start a new container!

visit localhost:3000

try editing a file like src/app.js

your changes should reflect after a moment on the website!

Activity: Docker for Development

Page 34: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

dev.Dockerfile

1 Start with Node.js

image

2 Make a directory to

put your code in, and set that

as your “working directory”

3 Install and start web

app when running the

container

Page 35: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

DIY!

We’ve just set up a completely containerized development environment

No need to install Node.js, just build the image and container and GO

Easy for every developer to reproduce

Page 36: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

However, dev.Dockerfile is not good for distribution

Activity: Docker for Distribution

DIY!

● Installs dependencies every time

● Webpack-Dev-Server has a lot of overhead

● No need for live-updating code

● No need for development dependencies

Page 37: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

build a lightweight image optimized for distribution

run the container to serve the website

upload to Docker Hub so anyone can download and deploy your image (optional!)

Activity: Docker for Distribution

DIY!

Page 38: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

to install dependencies and build the web app into ./build:

Docker Hub (optional): hub.docker.com

Useful Tidbits

hint: remember the Python server command in demo.Dockerfile!

copy local directory into a directory in the container:

build and (optional) publish your image:

Page 39: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

prod.Dockerfile

1 Start with Node.js image

2 Install Python

3 Copy your code into the

container

4 Install deps and build the web

app

5 Serve app from build directory

Page 40: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Solutions are available in the solutions branch:

github.com/ubclaunchpad/workshop-guide-to-docker/tree/solutions

Solutions

Page 41: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Q & A

Page 42: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Multi-Stage Builds

Advanced Usage

github.com/ubclaunchpad/inertia

Page 43: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Multi-Stage Builds

Advanced Usage

github.com/ubclaunchpad/inertia

Page 44: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

docker-compose

Advanced Usage

github.com/ubclaunchpad/rocket

Page 45: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Q & A

Page 46: A DEVELOPER’S GUIDE TO DOCKER - slides · to install dependencies and build the web app into ./build: Docker Hub (optional): hub.docker.com Useful Tidbits hint: remember the Python

Thank you!

UBCLAUNCHPAD.COM

@UBCLAUNCHPAD