Docker for Fun and Profit

32
Docker for Fun and Profit Kel Cecil @praisechaos

Transcript of Docker for Fun and Profit

Page 1: Docker for Fun and Profit

Docker for Fun and Profit

Kel Cecil@praisechaos

Page 2: Docker for Fun and Profit

So, what’s Docker?

❖ Docker is an open platform that allows developers and system administrators to abstract their applications for multiple platforms.

❖ We’ll focus our attention on Docker Engine today.

Page 3: Docker for Fun and Profit

Disrupt Chuck Norris Quotes!

❖ We’re going to containerize and run our simple app.

❖ Find the app and Dockerfile at: https://github.com/kelcecil/docker-techfest15

Page 4: Docker for Fun and Profit

Creating our Docker Image

❖ Start with building a Dockerfile.

❖ Image contains our app, dependencies and other required items.

❖ Images are read-only.

❖ Encourages immutable infrastructure!

Page 5: Docker for Fun and Profit

Docker Build Context

❖ Everything in context directory is sent when performing build.

❖ Anything in this context directory can be added to the image.

Page 6: Docker for Fun and Profit
Page 7: Docker for Fun and Profit

FROM specifies an image in which we’ll start building from.

Page 8: Docker for Fun and Profit

Images You’ll Want to Remember

❖ Images for Linux distros you know and love:

❖ ubuntu, fedora, debian

❖ Images for languages to get going quickly:

❖ golang, ruby, java

❖ My personal favorite:

❖ gliderlabs/alpine

Page 9: Docker for Fun and Profit

MAINTAINER sets metadata information on who keeps the

image up to date.

Page 10: Docker for Fun and Profit

USER sets the user to execute RUN and CMD commands as.

Page 11: Docker for Fun and Profit

RUN simply runs a shell command. Easy.

Page 12: Docker for Fun and Profit

COPY copies files from the Docker context into the

destination folder on image.

Page 13: Docker for Fun and Profit

Never allow your application to run as root. Be sure to switch to

a different user for executing your app.

Page 14: Docker for Fun and Profit

WORKDIR changes the current working directory.

Page 15: Docker for Fun and Profit

CMD sets the default command we’ll run if we don’t provide

with docker run.

Page 16: Docker for Fun and Profit

Building an Image From a Dockerfile

docker build -t chucksay:latest <context_dir>

❖ -t specifies the tag name for the image.

❖ <context_dir>

❖ Directory of Dockerfile and build context

Page 17: Docker for Fun and Profit
Page 18: Docker for Fun and Profit

Looking At Our Image

Page 19: Docker for Fun and Profit

Running Our Webservice in a Container

docker run -d -p 8080:4567 chucksay:latest

❖ -d to run detached

❖ -p specifies our ports internal to the container (right of the colon) and externally (left of the colon).

❖ “chucksay” is our tag name

Page 20: Docker for Fun and Profit

Running Our Container Interactively

docker run -it -p 8080:4567 chucksay:latest /bin/bash

❖ -it lets us interact with the container.

❖ -i is the interactive flag.

❖ -t allocates a pseudo-TTY

❖ Override the CMD we provided in the Dockerfile.

❖ Exiting bash stops the container.

Page 21: Docker for Fun and Profit

Docker Compose (fig)

❖ Keep container parameters in a JSON or YAML file.

❖ Build or run your application quite easily:

❖ docker-compose up -d

Page 22: Docker for Fun and Profit

Looking at Running Containers

docker ps

❖ Container ID

❖ Image

❖ Command

❖ Time since creation

❖ Status

❖ Ports

❖ Container Names

Page 23: Docker for Fun and Profit

Stopping Our Webservice Container

docker stop <container_id>

❖ <container_id> can be:

❖ Container ID

❖ Container Name

Page 24: Docker for Fun and Profit

What can we use containers for?

Page 25: Docker for Fun and Profit

Deploying Applications

❖ Package your application code, language specific dependencies, and system dependencies into a container.

❖ Push your images into a remote Docker repository.

❖ Pull them into production, your box, or where ever.

Page 26: Docker for Fun and Profit

Docker Repository

❖ Deploying a registry yourself:

❖ https://docs.docker.com/registry/deploying/

http://hub.docker.com http://quay.io

Page 27: Docker for Fun and Profit

Cluster Deployment

❖ Make orchestration easy with cluster management technologies:

❖ Kubernetes (http://kubernetes.io)

❖ Deis (http://deis.io)

❖ Plenty more…

Page 28: Docker for Fun and Profit

Try Docker for CI

❖ Try running for continuous integration tasks inside of a container.

❖ Updating your CI environment is as easy as a simple docker push.

❖ Prepare for different environment configurations by pushing additional images with tags.

❖ Pull the CI environment to developers boxes for easy access.

Page 29: Docker for Fun and Profit

Sharing With The World

❖ A few additional ideas to consider trying for your continued Docker education.

❖ Working with containers and Docker is best way to understand it.

Page 30: Docker for Fun and Profit

Lowering the Barrier to Open Source

❖ A hopeful open source developer or user needs an sane environment that works.

❖ User might only be interested performing a quick build.

❖ Containerized development environment allows an easy and quick start to the new developer.

Page 31: Docker for Fun and Profit

Sharing Dotfiles

❖ dotfile repositories are plentiful on Github.

❖ Take someone else’s configuration for a spin!

❖ Share your own configuration for tech cred.

Page 32: Docker for Fun and Profit

Thanks for playing along!

❖ Kel Cecil

❖ Twitter: @praisechaos

❖ http://www.kelcecil.com