Containerizing Your Dev Environment

54
Containerizing Your Dev Environment Laura Frank rheinwein @rhein_wein

Transcript of Containerizing Your Dev Environment

Page 1: Containerizing Your Dev Environment

Containerizing Your Dev Environment

Laura Frank

rheinwein

@rhein_wein

Page 2: Containerizing Your Dev Environment

rheinwein/hello-world-container-demo

Page 3: Containerizing Your Dev Environment

Containerization: what even is it?

Setting up a dev environment

Docker ecosystem nuts and bolts

Page 4: Containerizing Your Dev Environment
Page 5: Containerizing Your Dev Environment
Page 6: Containerizing Your Dev Environment

A tool for managing containers

• Managing code that goes in them • Executing code inside of them

Page 7: Containerizing Your Dev Environment

• 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

Page 8: Containerizing Your Dev Environment

A container is a virtualization layer — sort of like a VM — but with some fundamental differences

Page 9: Containerizing Your Dev Environment

hardware

host OS

hypervisor

$ guest OS

libraries

app 1

$ guest OS $ guest OS

libraries

app 2

libraries

app 1

Page 10: Containerizing Your Dev Environment

libraries

app 1

libraries

app 2

hardware

host OS

libraries

app 1

Page 11: Containerizing Your Dev Environment

hardware

host OS

container runtime engine

libraries libraries

app 1 app 1 app 2

Page 12: Containerizing Your Dev Environment

Containers have slightly more complexity

but

They reduce the amount of time/space resources needed to run your application

Page 13: Containerizing Your Dev Environment

• It’s fast! • It’s cheap! • It’s portable! • It’s safe!

Benefits of Containerization

Page 14: Containerizing Your Dev Environment

A Bird’s Eye View of Docker

Page 15: Containerizing Your Dev Environment

A tool for managing containers

• Managing code that goes in them • Executing code inside of them

Page 16: Containerizing Your Dev Environment

Engine Hub

docker.com

Page 17: Containerizing Your Dev Environment

registry.hub.docker.com

Page 18: Containerizing Your Dev Environment

Interacting with the Registry

• Push and pull —just like GitHub • Two types of images

• Services • Project base images

Page 19: Containerizing Your Dev Environment

Private Registries

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

Page 20: Containerizing Your Dev Environment

A tool for managing containers

• Managing code that goes in them

• Executing code inside of them

Page 21: Containerizing Your Dev Environment
Page 22: Containerizing Your Dev Environment

hardware

host OS

container runtime engine

libraries libraries

app 1 app 1 app 2

Page 23: Containerizing Your Dev Environment

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

Docker CLI

Page 24: Containerizing Your Dev Environment

• Docker daemon runs with each container

• Daemon exposes API with RESTful endpoints

• Using CLI == using API, just abstracted • You could build your own tooling

Docker API

Page 25: Containerizing Your Dev Environment

Setting Up Your Dev Environment with Docker

Page 26: Containerizing Your Dev Environment

Objectives

• Put code in container • Run the code inside the container • See application in web browser

Page 27: Containerizing Your Dev Environment

• A computer* • Code to run • Coffee (if you’d like)

Things you need

Installing Docker

Page 28: Containerizing Your Dev Environment
Page 29: Containerizing Your Dev Environment

Anything else? You need to use a lightweight VM.

Pro Tip: Boot2Docker (OSX and Windows)

Linux? Install Docker with official packages.

A Computer

Page 30: Containerizing Your Dev Environment

• Linked folders • Copied files • Port forwarding

Handling Abstraction

Code may seem out of reach, but can be managed using

Page 31: Containerizing Your Dev Environment

An image is controlled by a Dockerfiledocker build -t foo/bar .

docker pull foo/bar

Code to Run

All containers are based on images

Page 32: Containerizing Your Dev Environment

Code to Run

• Static: all files and code are contained in image

• Dynamic: link folders to actively modify code (development only)

SEHR WICHTIG!

Page 33: Containerizing Your Dev Environment

FROM centurylink/ruby-base:2.1.2

MAINTAINER Laura Frank <[email protected]>

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

Page 34: Containerizing Your Dev Environment

FROM centurylink/ruby-base:2.1.2

MAINTAINER Laura Frank <[email protected]>

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

Page 35: Containerizing Your Dev Environment

FROM centurylink/ruby-base:2.1.2

MAINTAINER Laura Frank <[email protected]>

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

Page 36: Containerizing Your Dev Environment

FROM centurylink/ruby-base:2.1.2

MAINTAINER Laura Frank <[email protected]>

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

Page 37: Containerizing Your Dev Environment

FROM centurylink/ruby-base:2.1.2

MAINTAINER Laura Frank <[email protected]>

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

Page 38: Containerizing Your Dev Environment

FROM centurylink/ruby-base:2.1.2

No need for version management, just use a different base image.

Base images are great!

Dockerfile

Page 39: Containerizing Your Dev Environment

• Available on Docker Hub • Maintained by other people (laziness++) • Repositories includes instructions for

bootstrapping • Images can be base images or actually

run services

Official Images

Page 40: Containerizing Your Dev Environment

The Easy Way: Boot2Docker

• Creates folder links for you • Obscures the separation between VM and

host • Super handy for quick, small projects • Not great for more complex systems

Page 41: Containerizing Your Dev Environment

The Hard Way: Vagrant

• Manually create folder links • Choose your own OS • Must ssh into VM • Great for more customization

Page 42: Containerizing Your Dev Environment

The Hard Way: Vagrant

config.vm.box_url = "http://storage.core-os.net/coreos/amd64-usr/alpha/coreos_production_vagrant.json"

config.vm.synced_folder "/Users/lfrank/CTL/panamax/panamax-api", "/var/panamax-api", id: "core", nfs: "true", mount_options: ['nolock,vers=3,udp']

Page 43: Containerizing Your Dev Environment

Either Way• Remember to forward ports in order to

access app in a browser

-p host_port:container_port

Page 44: Containerizing Your Dev Environment

(Sorry.)

…is kind of a pain.

Debugging in a Container

Page 45: Containerizing Your Dev Environment

Use a remote debugger.

Debugging in a Container

Page 46: Containerizing Your Dev Environment

If you’re a Rubyist, use Pry

require ‘pry’

class Thing def some_method binding.pry #some brilliant broken code end end

Debugging in a Container

Page 47: Containerizing Your Dev Environment

Application Templating

• Use your own images, or images from the Docker Registry

• Specify config options beforehand (like port forwarding)

• Run applications with one or two simple commands

Page 48: Containerizing Your Dev Environment

Standards tightly coupled with Docker

fig.sh

Dump requirements into fig.yml and run with fig up

Page 49: Containerizing Your Dev Environment

Docker workflow tool

Itself a containerized application

panamax.io

Uses CoreOS, Fleet, and etcd for orchestration and service discovery

Page 50: Containerizing Your Dev Environment

Templating language similar to fig

Supports remote deployments

panamax.io/get-panamax

Page 51: Containerizing Your Dev Environment

--- 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: []

Page 52: Containerizing Your Dev Environment

–Johnny Appleseed

“Type a quote here.”

Page 53: Containerizing Your Dev Environment

Additional Resources

Docker Hub: registry.hub.docker.com

Documentation: docs.docker.com

Boot2Docker: boot2docker.io

Panamax: panamax.io

CenturyLink Labs: centurylinklabs.com

Page 54: Containerizing Your Dev Environment

Thanks!

Laura Frank

rheinwein

@rhein_wein