Slide 1

Slide 1 text

Building Containerized Applications with Docker Laura Frank rheinwein @rhein_wein

Slide 2

Slide 2 text

Containerization: what is it? Using containers in your project Docker basics

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Docker != containers

Slide 5

Slide 5 text

A tool for managing containers • Managing code to run inside • Executing and running code Docker

Slide 6

Slide 6 text

• Run in a self-contained execution environment • Share the kernel of host system • Are isolated from other containers • Have fast boot times & low overhead Containers

Slide 7

Slide 7 text

A container is a virtualization layer — sort of like a VM — but with some fundamental differences If you deploy your applications in virtual machines, you can instead deploy them in containers.

Slide 8

Slide 8 text

hardware host OS hypervisor $ guest OS libraries web $ guest OS $ guest OS libraries DB libraries web

Slide 9

Slide 9 text

hardware host OS libraries web libraries DB libraries web

Slide 10

Slide 10 text

hardware host OS container runtime engine libraries libraries web web DB

Slide 11

Slide 11 text

Containers have slightly more complexity but They reduce the amount of time/space resources needed to run your application

Slide 12

Slide 12 text

• It’s fast! • It’s cheap! • It’s portable! • It’s safe! Benefits of Containerization

Slide 13

Slide 13 text

Docker Basics

Slide 14

Slide 14 text

A tool for managing containers • Managing code to run inside • Executing and running code Docker

Slide 15

Slide 15 text

Engine Hub docker.com

Slide 16

Slide 16 text

registry.hub.docker.com

Slide 17

Slide 17 text

Interacting with the Registry • Push and pull —just like GitHub • Two types of images • Services • Project base images

Slide 18

Slide 18 text

Private Registries • Get image from Docker Registry • Can have authentication • Push and pull just like with Docker Hub

Slide 19

Slide 19 text

A tool for managing containers • Managing code to run inside • Executing and running code Docker

Slide 20

Slide 20 text

hardware host OS container runtime engine libraries libraries app 1 app 1 app 2

Slide 21

Slide 21 text

• docker run my_image • docker pull your_image • docker images • docker ps Docker CLI

Slide 22

Slide 22 text

Using Containers in Your Application

Slide 23

Slide 23 text

• A computer • Application code • Coffee (if you’d like) Things you need Installing Docker

Slide 24

Slide 24 text

Anything else? You need to use a lightweight VM. Pro Tip: Boot2Docker (OSX and Windows) Linux? Install Docker with official packages. A Computer

Slide 25

Slide 25 text

To run your application in a container, you must first create an image Application Code All containers are based on images An image is controlled by a Dockerfile

Slide 26

Slide 26 text

Application Code Two ways to get images: docker pull foo/bar or docker run foo/bar 1. Pull down from Docker Hub docker build -t foo/bar . 2. Build from your own Dockerfile

Slide 27

Slide 27 text

• Available on Docker Hub • Maintained by other people (laziness++) • Repositories includes instructions for bootstrapping • Images can be base images or actually run services Application Code: Official Images

Slide 28

Slide 28 text

Application Code • Static: all files and code are contained in image • Dynamic: link folders to modify code (development only)

Slide 29

Slide 29 text

Application Code • Static: all files and code are contained in image • Dynamic: link folders to modify code (development only)

Slide 30

Slide 30 text

Application Code Using static images from the Docker Hub, you can create a containerized application without having to write your own code docker run mysql (…) docker run wordpress (…)

Slide 31

Slide 31 text

Application Code You can also package your own code and run it. docker run mysql (…) docker run my_image (…) docker build -t my_image .

Slide 32

Slide 32 text

FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank EXPOSE 4567 RUN mkdir -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile

Slide 33

Slide 33 text

FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank EXPOSE 4567 RUN mkdir -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile

Slide 34

Slide 34 text

FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank EXPOSE 4567 RUN mkdir -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile This copies code into the container STATIC! Not for apps under active development Great for dependencies and production applications

Slide 35

Slide 35 text

FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank EXPOSE 4567 RUN mkdir -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile This makes things happen to your code

Slide 36

Slide 36 text

FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank EXPOSE 4567 RUN mkdir -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile This makes the code happen

Slide 37

Slide 37 text

But this seems like a lot of tedious work, and I am very lazy.

Slide 38

Slide 38 text

Application Templating • Use your own images, or images from the Docker Registry • Specify config options beforehand • Run applications with one or two simple commands

Slide 39

Slide 39 text

Text-only templating tool fig.sh Dump requirements into fig.yml and run with fig up Fig aka Docker Compose

Slide 40

Slide 40 text

Templating language similar to Fig/Docker Compose Supports remote deployments panamax.io/get-panamax

Slide 41

Slide 41 text

--- name: Rails with PostgreSQL description: Rails with PostgreSQL images: - category: Web Tier name: Rails source: rheinwein/rails:latest description: Rails App type: Default expose: [] ports: - host_port: '8080' container_port: '3000' links: - service: Database alias: DB_1 environment: [] volumes: []

Slide 42

Slide 42 text

–Johnny Appleseed “Type a quote here.”

Slide 43

Slide 43 text

Docker Hub: registry.hub.docker.com Boot2Docker: boot2docker.io Panamax: panamax.io Rails Girls Summer of Code!: railsgirlssummerofcode.org rheinwein/hello-world-container-demo

Slide 44

Slide 44 text

Thanks! Laura Frank rheinwein @rhein_wein