Docker: Up and Running Introduction was a tech talk given at Code Youngstown on April 27, 2017 at the Drund office in Boardman, Ohio. The target audience is complete beginners to Docker and containers in general.
2. Introduction
Mark Beacom
● With Drund 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?
● “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
5.
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 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
9. 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.
10. 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.
11. 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
12. 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
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
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...
● 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
21. Honorable Mentions
● Docker Compose
○ Defining a whole containerized workload in a single file definition
● Task Schedulers and Container Orchestration
○ Marathon, Amazon ECS, Rancher, Nomad
22. 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