Docker Slides
Docker Slides
Problems:
• Huge Cost
• Slow Deployment
• Hard to Migrate
Pre-Virtualization
Hypervisor-based Virtualization
Benefits:
• Cost-Efficient
• Easy to Scale
Limitations:
Containers
Application A Application B
JRE 8 JRE 7
Container A Container B
Container Engine
Operating System/Kernel
Physical Server
Container Virtualization
Benefits:
Containers
• Cost-Efficient
• Fast Deployment
• Guaranteed Portability
Container Virtualization
Docker
Client-Server Architecture
Install Docker for Mac/Windows
Install Docker Software
Otherwise, you can skip this lecture and follow the installation guide of the next
lecture.
Install Docker Toolbox
Install Docker Toolbox
• You are using Mac and your Mac version is older than OS X 10.10.3.
• Or you are using Windows and your Windows version is older than
Windows 10.
• Or you want to install Docker Compose, Docker Machine or Kitematic
instead of Docker Engine.
Otherwise, you can skip this lecture and follow the installation guide of the previous
lecture.
If you already installed Docker for Mac/Windows, you can skip this lecture for now.
Important
Docker Concepts
Images
• Images are read only templates used to create containers.
• Images are created with the docker build command, either
by us or by other docker users.
• Images are composed of layers of other images.
• Images are stored in a Docker registry.
Containers
• If an image is a class, then a container is an instance of a
class - a runtime object.
• Containers are lightweight and portable encapsulations of
an environment in which to run applications.
• Containers are created from images. Inside a container, it
has all the binaries and dependencies needed to run the
application.
Registries and Repositories
• A registry is where we store our images.
• You can host your own registry, or you can use Docker’s
public registry which is called DockerHub.
• Inside a registry, images are stored in repositories.
• Docker repository is a collection of different docker images
with the same name, that have different tags, each tag
usually represents a different version of the image.
Why Using Official Images
• Clear Documentation
• Dedicated Team for Reviewing Image Content
• Security Update in a Timely Manner
Run our First Hello World Docker Container
Deep Dive into Docker Containers
• The new image is used for the next step in the Dockerfile. So each RUN
instruction will create a new image layer.
• The next time, if the instruction doesn't change, Docker will simply reuse
the existing layer.
Docker Cache
• Each time Docker executes an instruction it builds a new image layer.
• The next time, if the instruction doesn't change, Docker will simply reuse
the existing layer.
Dockerfile with Aggressive Caching
FROM ubuntu:14.04 reusing cache
Dockerapp Redis
How container links
work behind the scenes?
Benefits of Docker Container Links
• The main use for docker container links is when we build an
application with a microservice architecture, we are able to
run many independent components in different containers.
Container A Container B
Bridge (docker0)
Host
Internet
Host and Overlay Network
Host Network
• Unit tests should run as quickly as possible so that developers can iterate
much faster without being blocked by waiting for the tests results.
• Docker containers can spin up in seconds and can create a clean and
isolated environment which is great tool to run unit tests with.
Incorporating Unit Tests into Docker Images
Pros:
• A single image is used through development, testing and
production, which greatly ensures the reliability of our tests.
Cons:
• It increases the size of the image.
Fit Docker Technology into Continuous
Integration(CI) Process
What is Continuous Integration?
• Continuous integration is a software engineering practice in which
isolated changes are immediately tested and reported when they are
added to a larger code base.
Production Servers
CI process with Docker technologies involved
Staging / Production
Our Continuous Integration Pipeline
Github
Central Repository
for Version Control
Hosted Continuous
Integration Server
Text Direction: Introduction to Continuous Integration
• Generate a SSH key pair and save the private SSH key in your local
box and add the public key to your GitHub account.
• Then you can directly push your changes to github repository without
typing password.
How to check if SSH public key files are available on your local box?
The SSH public key file usually sits under ~/.ssh/ directory and ends with
.pub extension.
Link Circle CI with GitHub Account
Complete CI Workflow
Github
Central Repository
for Version Control
Staging / Production
Hosted Continuous
Integration Server
Tag the Docker Images with Two Tags
• On the other hand, there are still some people who are
reluctant to use Docker in production as they think docker
workflow is too complex or unstable for real life use cases.
Is Docker Production
Ready Now?
Concerns about Running Docker in Production
• There are still some missing pieces about Docker around data
persistence, networking, security and identity management.
80
80
80
Replicas
• We can connect to the nginx service
through a node which does NOT have
80 nginx replicas.
• Step 3: Let the second VM join the Swarm cluster as a worker node.
– docker swarm join
Provision a Swarm Cluster
• Step 1: Deploy two VMs, one will be used for the Swam manager node,
and the other one will be used as a worker node.
• Step 3: Let the second VM join the Swarm cluster as a worker node.
– docker swarm join
Provision a Swarm Cluster
• Step 1: Deploy two VMs, one will be used for the Swam manager node,
and the other one will be used as a worker node.
• Step 3: Let the second VM join the Swarm cluster as a worker node.
– docker swarm join
Docker Swarm commands
• docker swarm init
– Initialize a swarm. The docker engine targeted by this command
becomes a manager in the newly created single-node swarm.
• docker swarm join
– Join a swarm as a Swarm node.