Docker: Up and Running Mark Beacom
Introduction Mark Beacom ● With Drund since July 2014 ● Recently moved to DevOps from Backend ● I like coffee ● Rather be camping
What I’ll cover... ● What’s Docker? ● Benefits of Docker ● Images and Containers? ● The Docker ecosystem ● Dockerizing a flask web app ● Honorable mentions ● Live streaming: A resource intensive animal
What’s Docker? ● “Docker is the world’s leading software container platform.” ● Established in 2008 ● Current release: v1.13 ● Github: 43K+ Stars (now moby/moby) ● Software platform allowing for rapid build, test, and deploy of applications ● Packages software into standardized units called containers ● Runs images of containers ● Wraps everything needed to run: code, runtime, system tools, system libraries - anything that can be installed on a server
Benefits of Docker ● Avoid: “Works on my machine” problems when collaborating on code ● Ship Software… Faster (7x) ● Improved Developer Productivity ● Easy deployment, scaling, and rollbacks ● Avoid: Application configuration drift ● Reusability!
Images... ● Lightweight ● Stand-alone ● Executable ● Immutable ● Created with: docker build ● Listed with: docker images ● Deployable to registries ● Generated from a Dockerfile definition The basis of a Docker container
Containers..? What’s a container? ● Runtime instance of an image ● The standard unit where the application or service resides ● Runs completely isolated from the host environment (unless configured) ● Runs natively on the host machine’s kernel ● Created with: docker run
Docker CLI ● Listing active containers: docker ps ● Listing images: docker images ● Pulling images: docker pull alpine ○ Retrieves the alpine linux image from the Docker Hub repository ● Running an image: docker run alpine ls ○ Spins up a docker container running alpine with the ls command and returns the response.
Dockerize a Flask webapp! ● Collect the project source - We’re using Docker’s flask app example https://github.com/docker/labs/tree/master/beginner/flask-app ● Runs a python-based web application serving a single index template ● Defines all requirements, libraries, and configuration settings.
Anatomy of our Dockerfile ● FROM - Defines the base ● RUN - Executes commands during the build process ● COPY - Copies file(s) to the image ● EXPOSE - Exposes the port ● CMD - The default command executed at runtime
Initiating a Docker build... docker build -t docker-demo . ● Results in a build with 9 steps ● Pulls the Alpine linux image from Docker Hub ● Runs our commands ● Copies assets ● Exposes the necessary port to the host
Building the image ● Step 1: FROM alpine:latest ● Step 2: RUN apk add --update py2-pip
Building the image ● Step 3: RUN pip install --upgrade pip ● Step 4: COPY requirements.txt /usr/src/app/
Building the image ● Step 5: RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt
Building the image ● Step 6: COPY app.py /usr/src/app/ ● Step 7: COPY templates/index.html /usr/src/app/templates/ ● Step 8: EXPOSE 5000
Building the image ● Step 9: CMD python /usr/src/app/app.py
Running the container ● Mapping ports at runtime: ○ docker run -p 4000:5000 docker-demo ○ -p <host_port>:<container_port> ○ If no port is specified, a host port will be assigned randomly ● Naming the container for easier access and differentiation ○ docker run -p 4000:5000 --name demo docker-demo ○ --name <name> ○ If not specified, Docker will assign a random name to the container instance
Cleaning up... ● List Docker containers: docker ps ● Stop a running container: docker stop <name_or_hash> ● Remove a stopped container: docker rm <name_or_hash> ● List images: docker images ● Remove an unused image: docker rmi <name_or_hash> A better way… ● docker run with --rm ● Automatically removes the container on exit
Live Demo Risky business… Let’s try it out!
Honorable Mentions ● Docker Compose ○ Defining a whole containerized workload in a single file definition ● Task Schedulers and Container Orchestration ○ Marathon, Amazon ECS, Rancher, Nomad
Our use case for live streaming ● Deployed to Amazon Elastic Container Service ● Dynamically scales underlying resource pool based on utilization ● Individual transcoding containers independent for each stream ● Only use resources when the platform is in use ● Live stream capacity only limited by the maximum number of instances we can provision on AWS
Question and Answer

Docker Up and Running Introduction

  • 1.
    Docker: Up andRunning Mark Beacom
  • 2.
    Introduction Mark Beacom ● WithDrund since July 2014 ● Recently moved to DevOps from Backend ● I like coffee ● Rather be camping
  • 3.
    What I’ll cover... ●What’s Docker? ● Benefits of Docker ● Images and Containers? ● The Docker ecosystem ● Dockerizing a flask web app ● Honorable mentions ● Live streaming: A resource intensive animal
  • 4.
    What’s Docker? ● “Dockeris the world’s leading software container platform.” ● Established in 2008 ● Current release: v1.13 ● Github: 43K+ Stars (now moby/moby) ● Software platform allowing for rapid build, test, and deploy of applications ● Packages software into standardized units called containers ● Runs images of containers ● Wraps everything needed to run: code, runtime, system tools, system libraries - anything that can be installed on a server
  • 6.
    Benefits of Docker ●Avoid: “Works on my machine” problems when collaborating on code ● Ship Software… Faster (7x) ● Improved Developer Productivity ● Easy deployment, scaling, and rollbacks ● Avoid: Application configuration drift ● Reusability!
  • 7.
    Images... ● Lightweight ● Stand-alone ●Executable ● Immutable ● Created with: docker build ● Listed with: docker images ● Deployable to registries ● Generated from a Dockerfile definition The basis of a Docker container
  • 8.
    Containers..? What’s acontainer? ● Runtime instance of an image ● The standard unit where the application or service resides ● Runs completely isolated from the host environment (unless configured) ● Runs natively on the host machine’s kernel ● Created with: docker run
  • 9.
    Docker CLI ● Listingactive containers: docker ps ● Listing images: docker images ● Pulling images: docker pull alpine ○ Retrieves the alpine linux image from the Docker Hub repository ● Running an image: docker run alpine ls ○ Spins up a docker container running alpine with the ls command and returns the response.
  • 10.
    Dockerize a Flaskwebapp! ● Collect the project source - We’re using Docker’s flask app example https://github.com/docker/labs/tree/master/beginner/flask-app ● Runs a python-based web application serving a single index template ● Defines all requirements, libraries, and configuration settings.
  • 11.
    Anatomy of ourDockerfile ● FROM - Defines the base ● RUN - Executes commands during the build process ● COPY - Copies file(s) to the image ● EXPOSE - Exposes the port ● CMD - The default command executed at runtime
  • 12.
    Initiating a Dockerbuild... docker build -t docker-demo . ● Results in a build with 9 steps ● Pulls the Alpine linux image from Docker Hub ● Runs our commands ● Copies assets ● Exposes the necessary port to the host
  • 13.
    Building the image ●Step 1: FROM alpine:latest ● Step 2: RUN apk add --update py2-pip
  • 14.
    Building the image ●Step 3: RUN pip install --upgrade pip ● Step 4: COPY requirements.txt /usr/src/app/
  • 15.
    Building the image ●Step 5: RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt
  • 16.
    Building the image ●Step 6: COPY app.py /usr/src/app/ ● Step 7: COPY templates/index.html /usr/src/app/templates/ ● Step 8: EXPOSE 5000
  • 17.
    Building the image ●Step 9: CMD python /usr/src/app/app.py
  • 18.
    Running the container ●Mapping ports at runtime: ○ docker run -p 4000:5000 docker-demo ○ -p <host_port>:<container_port> ○ If no port is specified, a host port will be assigned randomly ● Naming the container for easier access and differentiation ○ docker run -p 4000:5000 --name demo docker-demo ○ --name <name> ○ If not specified, Docker will assign a random name to the container instance
  • 19.
    Cleaning up... ● ListDocker containers: docker ps ● Stop a running container: docker stop <name_or_hash> ● Remove a stopped container: docker rm <name_or_hash> ● List images: docker images ● Remove an unused image: docker rmi <name_or_hash> A better way… ● docker run with --rm ● Automatically removes the container on exit
  • 20.
    Live Demo Risky business…Let’s try it out!
  • 21.
    Honorable Mentions ● DockerCompose ○ Defining a whole containerized workload in a single file definition ● Task Schedulers and Container Orchestration ○ Marathon, Amazon ECS, Rancher, Nomad
  • 22.
    Our use casefor live streaming ● Deployed to Amazon Elastic Container Service ● Dynamically scales underlying resource pool based on utilization ● Individual transcoding containers independent for each stream ● Only use resources when the platform is in use ● Live stream capacity only limited by the maximum number of instances we can provision on AWS
  • 23.