SlideShare a Scribd company logo
Speaker
Introduction to Docker and
Containers
Agenda of the Day
• Introduction to Docker
• What and Why of Containers?
• Understanding Docker Lifecycle
• Building docker images using Dockerfile
• What is Docker Compose?
Docker
Leading open-source containerization
platform
Supported natively in Azure
Docker containers wrap up a piece of software
in a complete filesystem that contains
everything it needs to run: code, runtime,
system tools, system libraries – anything you
can install on a server. This guarantees that it
will always run the same, regardless of the
environment it is running in
Docker Architecture
Docker CLI
• Command-line interface for Docker, available for Linux, OS X,
and Windows (available separately or as part of Docker Toolbox)
Running a Container
docker run -i -t ubuntu /bin/bash
Containers
Lightweight alternative to virtual machines
Smaller, less expensive, faster to start up, and self-contained
Host Operating System
Hypervisor
Guest OS
Libraries
App
Guest OS
Libraries
App
Guest OS
Libraries
App
Operating System
Container Engine
Libraries
App
Libraries
App
Libraries
App
Virtual Machines
Containers
Processes in containers are isolated from other
containers in user space, but share the kernel with the host and other
containers
Differences in underlying OS and infrastructure
are abstracted away, streamlining “deploy anywhere” approach
Containers can be created almost instantly, enabling rapid scale-
up and scale-down in response to changes in demand
Containers
Containers
Semantics
Common Docker CLI Commands
docker run - Use an image to run a container
docker pull - Pull an image from a registry
docker build - Build a Docker image
docker exec - Execute a command in a container
docker stop - Stop a running container
docker images - List available Docker images
docker ps - List running Docker containers
Running Containers on Linux
Container A
App 1
Container B
App 2
Container C
App 3
Linux-Based Host Operating System
Infrastructure
Container A
• Isolation from kernel-level container support
• Containers are started from images
Container B
• Binaries depend on specific OS/kernel
Container C
�� No guest OS needed
What is Docker?
Server Docker Daemon
Rest API
Client Docker CLI Manages
• Container
• Network
• Image
• Data Volumes
Container Anatomy
• Container images
• The container
• Container tooling
Container layer (Thin r/w)
Your Application
Updates/Patches/Additional tools
Frameworks and Tools
Base OS layer
Dockerfile to Create Images
What is Docker Compose?
• Used to instance multiple containers
• Can reference Dockerfiles
and/or images
• Paired with docker-compose.yml
Web Frontend
SQL Server on Linux
Web API Redis Cache
Docker-Compose Structure
Version: ‘3.0’
Services:
service-name:
image: docker-image
image: how to build
depends on:
-other services
environment:
-key/value pairs
ports:
-port mapping
network:
network-name:
volumes:
volume-name:
CI/CD for Containers
DevOps flow – CD push to cluster

More Related Content

Docker.pptx

  • 2. Agenda of the Day • Introduction to Docker • What and Why of Containers? • Understanding Docker Lifecycle • Building docker images using Dockerfile • What is Docker Compose?
  • 3. Docker Leading open-source containerization platform Supported natively in Azure Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in
  • 5. Docker CLI • Command-line interface for Docker, available for Linux, OS X, and Windows (available separately or as part of Docker Toolbox)
  • 6. Running a Container docker run -i -t ubuntu /bin/bash
  • 7. Containers Lightweight alternative to virtual machines Smaller, less expensive, faster to start up, and self-contained Host Operating System Hypervisor Guest OS Libraries App Guest OS Libraries App Guest OS Libraries App Operating System Container Engine Libraries App Libraries App Libraries App Virtual Machines Containers
  • 8. Processes in containers are isolated from other containers in user space, but share the kernel with the host and other containers Differences in underlying OS and infrastructure are abstracted away, streamlining “deploy anywhere” approach Containers can be created almost instantly, enabling rapid scale- up and scale-down in response to changes in demand Containers
  • 11. Common Docker CLI Commands docker run - Use an image to run a container docker pull - Pull an image from a registry docker build - Build a Docker image docker exec - Execute a command in a container docker stop - Stop a running container docker images - List available Docker images docker ps - List running Docker containers
  • 12. Running Containers on Linux Container A App 1 Container B App 2 Container C App 3 Linux-Based Host Operating System Infrastructure Container A • Isolation from kernel-level container support • Containers are started from images Container B • Binaries depend on specific OS/kernel Container C • No guest OS needed
  • 13. What is Docker? Server Docker Daemon Rest API Client Docker CLI Manages • Container • Network • Image • Data Volumes
  • 14. Container Anatomy • Container images • The container • Container tooling Container layer (Thin r/w) Your Application Updates/Patches/Additional tools Frameworks and Tools Base OS layer
  • 16. What is Docker Compose? • Used to instance multiple containers • Can reference Dockerfiles and/or images • Paired with docker-compose.yml Web Frontend SQL Server on Linux Web API Redis Cache
  • 17. Docker-Compose Structure Version: ‘3.0’ Services: service-name: image: docker-image image: how to build depends on: -other services environment: -key/value pairs ports: -port mapping network: network-name: volumes: volume-name:
  • 19. DevOps flow – CD push to cluster

Editor's Notes

  1. Docker (www.docker.com) isn't the world's only containerization platform, but it is the most popular. It is free, open-source, and Linux-based, with Windows support (Windows Server 2016) in the works. It has earned massive mindshare in the developer community. And with Azure Container Service, you can deploy Docker containers to Azure with minimal effort. Moreover, Docker containers are easily moved between Azure and Amazon Web Services (AWS), affording developers portability between cloud platforms.
  2. Docker utilizes a client-server architecture. You execute Docker commands through a Docker client such as the Docker CLI or Kitematic. The client uses REST commands to communicate with the Docker daemon running on a Docker host such as the Azure Container services. These commands can be used to push, pull (docker pull), and create Docker images, to run them in containers, and to manage those containers. Images can be built with the docker build command, and they can be stand-alone, or they can "inherit" from other images. Images are stored in Docker registries, which can be public or private, local or remote. Docker Hub is a popular public registry that is managed by Docker; it contains a "huge collection" of images that anyone may use. The docker run command runs a container using an image as a template.
  3. The Docker Client, also known as the Docker CLI, is the primary tool you use to manage Docker containers. You can download container images from repositories such as Docker Hub, build container images, run container instances, list container images and instances, and much more. After connecting to Azure Container Service using SSH, you can use port forwarding to execute commands locally that act on an Azure Container Service running in the cloud. In this example, the -H switch used with the docker commands forwards commands sent to port 22375 on localhost to the Azure Container Services via SSH.
  4. This command pulls the image named "Ubuntu" from Docker Hub (or a local registry if the image is cached there) and runs it interactively in a container. "Interactively" means standard input, output, and error are connected locally so you can provide input to the container and see its output. Of course, you are not limited to the "Ubuntu" image. You can specify other images and even create images of your own with docker build. Where the container runs depends on the context. The container can run locally in a docker host (for example, a VM on Windows), or it can remotely if you connect to a remote Docker daemon (for example, one running in Azure) via SSH tunneling and use port forwarding to forward docker commands to the daemon.
  5. A virtual machine is -- well -- a virtualized machine created and managed by a hypervisor such as VirtualBox or Hyper-V. Even though a VM runs on a machine that has an operating system, each VM requires its own complete operating system, even if it's the same operating system as the host OS. VMs offer a very high degree of isolation, but at a cost: longer startup times, lower portability (ever tried to move a 127 GB virtual hard disk, or VHD, from one PC to another?), and higher memory requirements. Containers, by contrast, leverage the operating system that is already in place but offer nearly as much separation. RAM requirements are lower since the OS isn't being duplicated in each container, and cost is lower, too, because while cloud platforms typically charge for each VM, a single VM can host multiple container instances.
  6. These are some of the most commonly used docker commands. You can also use docker push to push an image to a registry such as Docker Hub. Also, docker ps is often accompanied by a -a switch to list all containers, including those that are no longer running, while docker rm and docker rmi are used to delete (remove) containers and images, respectively. The docker build command uses a Dockerfile (a text file containing build commands) and a "context" -- for example, a specified directory in the file system -- to build Docker images.
  7. Before we talk about Docker, let’s give a little bit of background on containers. The easiest way to explain containers is to start thinking about a Virtual Machine. A Virtual Machine is a machine that runs within another Computer. The virtual machines use virtualized hardware. Other than that, it is the same as a physical machine. They need their own OS and drivers, etc. A container does not run on virtualized hardware. It runs on the existing OS and uses the same processes and drivers, but in isolation. Storing only the changes from the host OS. This means you cannot run a Windows Container on Linux and vice versa. Because a container does need its own OS, they are small and fast. And because they are small, you can run many container instances on one host.
  8. And then Docker. Docker is an open platform for developing, shipping, and running applications. Docker consists of a few components. The Docker Daemon which is the communication engine between host machine and container, A REST Api to interact with the daemon and the Docker CLI. The CLU uses the API in a user-friendly way to allow users to work with Docker.
  9. When we talk about docker and containers, we also need to talk about images, since a container is the running instance of a container image. Lets first take a look at what an image is. To run a container, we need an image. An image consists of several layers. The first layer of an image is always the base operating system layer. This is where all the required files are that are needed together with the shared operating system kernel to provide the operating system services. On top of the operating system layer, you can create new layers. Each layer is a delta added to the base layer. For example, if I would like to have a container running NGINX, we need to add a layer that installs this. After you commit the changes to the new image, you can use this image as the starting point of a new image that .e.g. adds the NODEJS capabilities on top of that. This way you constantly add layers to the images, until you have a container that is fully capable of running your own application The container is a running instance of the image. This means the operating system adds a thin read/write layer on top of the container image. The nice thing about a container is that when you stop it and start a new instance, you always start from that clean image. This way you never pick up any changes on the image, ensuring there is no drift in e.g. configuration. We call this the immutability of the image. Once you created an image, you can not change it. Changing it means you create a new image.
  10. The great part about Docker is that you can do everything as code. Either by running commands in the Docker CLI or by creating Docker Files that describe how a container image should look like. In the example, you can see that the Docker file builds on top of a node base images, exposes a port 3000, creates a new directory and then copies files and runs NPM install, When running a Docker build command, the Docker file is executed and the immutable image is created.
  11. When an application consists of multiple parts (e.g., an API, Web application and database) you need to run all containers at the same time and connect them in a network. To facilitate orchestration of multiple containers, you can use Docker-compose. Docker-compose allows you to describe a composition that uses either existing container images or builds them om the fly using the already created docker files
  12. Docker compose files are described in YAML where you can specify both the build and run parameters.