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 Docker CLI command Run container with interactive terminal Pull " ubuntu " image from Docker Hub or local registry Command to execute in the container
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
Dependencies: Every application has it’s own dependencies which includes both software (services, libraries) and hardware (CPU, memory, storage) Virtualization: Container engine is a light weight virtualization mechanism which isolates these dependencies per each application by packaging them into virtual containers Shared host OS: Processes in containers are isolated from other containers in user space, but share the kernel with the host and other containers Flexible: Differences in underlying OS and infrastructure are abstracted away, streamlining “deploy anywhere” approach Fast: Containers can be created almost instantly, enabling rapid scale-up and scale-down in response to changes in demand Containers Technical overview App A Host OS w/Container support Server / Hypervisor Bins/libraries Container Bins/libraries App B Container
Containers How do they differ from virtual machines? Dependencies: Each virtualized app includes the app itself, required binaries and libraries and a guest OS, which may consist of multiple GB of data Independent OS: Each VM can have a different OS from other VMs, along with a different OS to the host itself Flexible: VMs can be migrated to other hosts to balance resource usage and for host maintenance without downtime Secure: High levels of resource and security isolation for key virtualized workloads App A Host OS w/Container support Server / Hypervisor Bins/libraries Container Bins/libraries App B Virtual Machine Host OS w/Container support
Semantics What’s the difference between a Docker File, Image and Container? Docker File: Defines source image and commands to execute to build a Docker Image Defines image to build… (‘ docker build’) Docker Image: Images are stored in a registry and are a immutable copy of the application Defines packaged build…(‘ docker run’) Docker Container: This is the running instance of a Docker Image Defines running image…(‘ docker ps’ )
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 Binaries/Libraries Container B App 2 Binaries/Libraries Container C App 3 Binaries/Libraries Linux-Based Host Operating System with container support (e.g. Debian ) Infrastructure Host server (physical or virtual) 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 Disclaimer: This is one way of doing it (although very common) and there are million other ways and tools/services Local Dev Source Repo CI Docker Rep Master Master Master D D