Container-based virtualization: Docker

Similar documents
An introduction to Docker

Introduction to Containers

Apache Storm: Hands-on Session A.A. 2016/17

CS-580K/480K Advanced Topics in Cloud Computing. Container III

Run containerized applications from pre-existing images stored in a centralized registry

Investigating Containers for Future Services and User Application Support

Think Small to Scale Big

Network softwarization Lab session 2: OS Virtualization Networking

Docker 101 Workshop. Eric Smalling - Solution Architect, Docker

Who is Docker and how he can help us? Heino Talvik

Docker und IBM Digital Experience in Docker Container

Index. Bessel function, 51 Big data, 1. Cloud-based version-control system, 226 Containerization, 30 application, 32 virtualize processes, 30 31

Introduction to containers

Docker A FRAMEWORK FOR DATA INTENSIVE COMPUTING

Getting Started With Containers

DGX-1 DOCKER USER GUIDE Josh Park Senior Solutions Architect Contents created by Jack Han Solutions Architect

What s Up Docker. Presented by Robert Sordillo Avada Software

[Docker] Containerization

A Hands on Introduction to Docker

Docker DCA EXAM. m/ Product: Demo. For More Information: Docker Certified Associate

Travis Cardwell Technical Meeting

Docker Swarm installation Guide

Dockerfile & docker CLI Cheat Sheet

agenda PAE Docker Docker PAE

Midterm Presentation Schedule

Code: Slides:

Introduction to Container Technology. Patrick Ladd Technical Account Manager April 13, 2016

Best Practices for Developing & Deploying Java Applications with Docker

Arup Nanda VP, Data Services Priceline.com

Red Hat Containers Cheat Sheet

Docker Cheat Sheet. Introduction

docker & HEP: containerization of applications for development, distribution and preservation

DevOps Workflow. From 0 to kube in 60 min. Christian Kniep, v Technical Account Manager, Docker Inc.

ovirt and Docker Integration

Harbor Registry. VMware VMware Inc. All rights reserved.

Containers. Pablo F. Ordóñez. October 18, 2018

Containers, Serverless and Functions in a nutshell. Eugene Fedorenko

Docker and Oracle Everything You Wanted To Know

USING DOCKER FOR MXCUBE DEVELOPMENT AT MAX IV

Important DevOps Technologies (3+2+3days) for Deployment

Real world Docker applications

DCCN Docker Swarm Cluster Documentation

SQL Server inside a docker container. Christophe LAPORTE SQL Server MVP/MCM SQL Saturday 735 Helsinki 2018

Getting Started With Amazon EC2 Container Service

Dockerize Your IT! Centrale Nantes Information Technology Department Yoann Juet Dec, 2018

Deployment Patterns using Docker and Chef

Infrastructure at your Service. Oracle over Docker. Oracle over Docker

Kubernetes: Integration vs Native Solution

Deploying Persistent Storage in Docker Swarm using Pure Storage. Simon Dodsley, Director of New Stack Technologies

OS Virtualization. Linux Containers (LXC)

Developing and Testing Java Microservices on Docker. Todd Fasullo Dir. Engineering

Oh.. You got this? Attack the modern web

A REFERENCE ARCHITECTURE FOR DEPLOYING WSO2 MIDDLEWARE ON KUBERNETES

Orchestration in Docker

/ Cloud Computing. Recitation 5 February 14th, 2017

Shifter at CSCS Docker Containers for HPC

Infoblox Kubernetes1.0.0 IPAM Plugin

Kuber-what?! Learn about Kubernetes

INDIGO PAAS TUTORIAL. ! Marica Antonacci RIA INFN-Bari

ASP.NET Core & Docker

Fixing the "It works on my machine!" Problem with Docker

/ Cloud Computing. Recitation 5 September 26 th, 2017

Cross platform enablement for the yocto project with containers. ELC 2017 Randy Witt Intel Open Source Technology Center

Engineering Robust Server Software

Creating pipelines that build, test and deploy containerized artifacts Slides: Tom Adams

By: Jeeva S. Chelladhurai

Search Engines and Time Series Databases

Containerisation with Docker & Kubernetes

TECHNICAL BRIEF. Scheduling and Orchestration of Heterogeneous Docker-Based IT Landscapes. January 2017 Version 2.0 For Public Use

Table of Contents 1.1. Introduction. Overview of vsphere Integrated Containers 1.2

The Galaxy Docker Project. our hands-on tutorial

WHITE PAPER. RedHat OpenShift Container Platform. Benefits: Abstract. 1.1 Introduction

Table of Contents DevOps Administrators

Applications with R and Docker

Docker Enterprise Edition 2.0 Platform Public Beta Install and Exercises Guide

VNS3 3.5 Container System Add-Ons

Docker II - Judgement Day

Virtual Infrastructure: VMs and Containers

Docker. Master the execution environment of your applications. Aurélien Dumez. Inria Bordeaux - Sud-Ouest. Tuesday, March 24th 2015

Buenos Aires 31 de Octubre de 2018

Search and Time Series Databases

GitLab-CI and Docker Registry

Kubernetes The Path to Cloud Native

Container Orchestration on Amazon Web Services. Arun

Microsoft Cloud Workshop. Containers and DevOps Hackathon Learner Guide

Build your dev environment with Docker.

Red Hat Atomic Details Dockah, Dockah, Dockah! Containerization as a shift of paradigm for the GNU/Linux OS

Data Acquisition. The reference Big Data stack

TEN LAYERS OF CONTAINER SECURITY

IBM 开源技术微讲堂容器技术与微服务系列

Distributed Computing Framework Based on Software Containers for Heterogeneous Embedded Devices

An Introduction to Kubernetes

DevOps Technologies. for Deployment

Dockercon 2017 Networking Workshop

Cloud I - Introduction

Docker Networking Deep Dive online meetup

Knative: Building serverless platforms on top of Kubernetes

Docker on VDS. Aurelijus Banelis

Portable, lightweight, & interoperable Docker containers across Red Hat solutions

Container System Overview

Transcription:

Università degli Studi di Roma Tor Vergata Dipartimento di Ingegneria Civile e Ingegneria Informatica Container-based virtualization: Docker Corso di Sistemi Distribuiti e Cloud Computing A.A. 2018/19 Valeria Cardellini Case study: Docker Lightweight, open and secure container-based virtualization Containers include the application and all of its dependencies, but share the kernel with other containers Containers run as an isolated process in userspace on the host operating system Containers are also not tied to any specific infrastructure 1

Docker internals Docker is written in Go language With respect to other OS-level virtualization solutions, Docker is a higher-level platform that exploits Linux kernel mechanisms such as cgroups and namespaces First versions based on LXC Then based on its own libcontainer runtime that uses Linux kernel namespaces and cgroups directly libcontainer (now included in opencontainers/runc): crosssystem abstraction layer aimed to support a wide range of isolation technologies Dockers adds to LXC Portable deployment across machines Versioning, i.e., git-like capabilities Component reuse Shared libraries, see Docker Hub hub.docker.com 2 Docker engine Docker Engine: clientserver application composed by: A server, called daemon process A REST API which specifies interfaces that programs can use to control and interact with the daemon A command line interface (CLI) client See https://docs.docker.com/engine/docker-overview/ 3

Docker architecture Docker uses a client-server architecture The Docker client talks to the Docker daemon, which builds, runs, and distributes Docker containers Client and daemon communicate via sockets or REST API 4 Docker image Read-only template containing instructions for creating a Docker container Described in text file called Dockerfile, with simple, well-defined syntax The Build component of Docker Enables the distribution of applications with their runtime environment Incorporates all the dependencies and configuration necessary for it to run, eliminating the need to install packages and troubleshoot Target machine must be Docker-enabled The Docker Image Can be pulled and pushed towards a registry Image names have the form [registry/][user/]name[:tag] Default for tag is latest 5

Docker image: Dockerfile Images can be created from a Dockerfile and a context: Dockerfile: instructions to assemble the image Context: set of files (e.g., application, libraries) Often, an image is based on another image (e.g., ubuntu) Example of a Dockerfile 6 Docker image: build Build an image from a Dockerfile $ docker run [OPTIONS] PATH URL - $ docker build -t hello-world. 7

Docker image: layers Layered image Each image consists of a series of layers Docker uses union file systems to combine these layers into a single unified view Layers are stacked on top of each other to form a base for a container s root file system Based on the copy-on-write (COW) principle 8 Docker image: layers Layering pros - Enable layer sharing and reuse, installing common layers only once and saving bandwidth and storage space - Manage dependencies and separate concerns - Facilitate software specializations - See https://docs.docker.com/storage/storagedriver/ 9

Docker image: storage Containers should be stateless. Ideally: Very little data is written to the container s writable layer Data should be written on Docker volumes Nevertheless: some workloads require to write data to the container s writable layer The storage driver controls how images and containers are stored and managed on the Docker host Multiple choices for the storage driver - Including AuFS and OverlayFS (both operate at file level), Device Mapper, Btrfs and zfs (that operate at block level) - Storage driver s choice can affect the performance of the containerized applications - See https://dockr.ly/2fstue6 10 Docker container and registry Docker container: runnable instance of a Docker image Run, start, stop, move, or delete a container using Docker API or CLI commands The Run component of Docker - Docker containers are stateless: when a container is deleted, any data written that is not stored in a data volume is deleted along with the container Docker registry: stateless server-side application that stores and lets you distribute Docker images - Provides an open library of images - The Distribute component of Docker - Docker-hosted registries: Docker Hub, Docker Store (open source and enterprise verified images) 11

Docker: run command When you run a container whose image is not yet installed but is available on Docker Hub Courtesy of Docker in Action by J. Nickoloff 12 State transitions of Docker containers Courtesy of Docker in Action by J. Nickoloff 13

Commands: Docker info Obtain detailed info on your Docker installation $ docker info E.g., to know the used storage driver (e.g., AuFS) 14 Commands: image handling List images on host (i.e., local repository) $ docker images or $ docker image ls - To list every image, including intermediate image layers: $ docker images a or $ docker image ls a Options to list images by name and tag, to list image digests (sha256), to filter images, to format the output, e.g., $ docker images --filter reference=ubuntu Inspect an image Display detailed information, including image layers $ docker [image] inspect imageid Remove an image $ docker rmi imageid or $ docker image rm imageid Can also use imagename instead of imageid 15

Command: run $ docker run [OPTIONS] IMAGE [COMMAND] [ARGS] Most common options --name assign a name to the container d detached mode (in background) i interactive (keep STDIN open even if not attached) -t allocate a pseudo-tty --expose expose a range of ports inside the container -p publish a container's port or a range of ports to the host v bind and mount a volume e set environment variables --link add link to other containers The Hello World container $ docker run alpine /bin/echo 'Hello world' - Alpine: lightweight Linux distro with reduced image size 16 Commands: containers management List containers Only running containers: $ docker ps Alternatively, $ docker container ls All containers (even stopped or killed containers): $ docker ps -a Container lifecycle Stop running container $ docker stop containerid Start stopped container $ docker start containerid Kill running container $ docker kill containerid Remove container (need to stop the container before attempting removal) $ docker rm containerid Can also use containername instead of containerid 17

Commands: containers management Inspect a container Most detailed view of the environment in which a container was launched $ docker inspect containerid Copy files from and to docker container $ docker cp containerid:path localpath $ docker cp localpath containerid:path 18 Examples of using Docker Run a nginx Web server inside a container - Also bind the container to a specific port $ docker run d p 80:80 --name web nginx Send HTTP request through Web browser - First retrieve the hostname of the host machine Send HTTP request through an interactive container using the Docker internal network $ docker run -i -t --link web:web --name web_test busybox / # wget -O - http://web:80/ / # exit To not use --link, let us define a bridge network $ docker network create my_net $ docker run -d p 80:80 --name web --net=my_net nginx $ docker run i -t --net=my-net --name web_test busybox /#... --link: legacy flag to manually create links between the containers wget: -O FILE Save to FILE ('-' for stdout) 19

Examples of using Docker Sending an HTTP request through an Alpine Linux container with curl installed and set as entrypoint $ docker run --rm byrnedo/alpine-curl http:// Checking the logs of the container $ docker logs containerid_or_name 20 Examples of using Docker Running Apache web server with minimal index page Define container image with Dockerfile Define image starting from Ubuntu, install and configure Apache Incoming port set to 80 using EXPOSE instruction FROM ubuntu # Install dependencies RUN apt-get update RUN apt-get -y install apache2 # Install apache and write hello world message RUN echo 'Hello World!' > /var/www/html/index.html # Configure apache RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh RUN echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh RUN echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh RUN echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh RUN chmod 755 /root/run_apache.sh EXPOSE 80 CMD /root/run_apache.sh 21

Examples of using Docker Build container image from Dockerfile $ docker build -t hello-apache. Run container and bind $ docker run -d -p 80:80 hello-apache Option p: publish container port (80) to host port (80) 22 Examples of using Docker Stopping and removing a container $ docker ps $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2b2b39d05fe0 hello_world "/bin/sh -c /root/ru " 3 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp pedantic_austin $ docker stop containerid_or_name $ docker ps -a $ docker rm containerid_or_name Stopping and removing all container $ docker stop $(docker ps -a q) $ docker rm $(docker ps -a q) 23

Examples of using Docker Running a Python web app in Docker See https://docs.docker.com/get-started/part2/ Define container image with Dockerfile Define image with Python runtime and Python app Incoming port set to 80 using EXPOSE instruction Write app code in Python using Flask and Redis packages and create file requirements.txt to specify those packages needed by app Redis: in-memory data store Redis is used to keep the counter of the number of visits to web app Build container image $ docker build -t friendlyhello. Run container and bind $ docker run -d -p 4000:80 friendlyhello Option p: publish container port (80) to host port (4000) 24 Multi-container Docker applications How to run multi-container Docker apps? Docker Compose Deployment on single host Docker Swarm The native orchestration tool for Docker Deployment on multiple hosts Kubernetes 25

Docker Compose To coordinate the execution of multiple containers, we can use Docker Compose See https://docs.docker.com/compose/ Docker Compose Not bundled within Docker installation (on Linux) Can be installed following the official Docker documentation https://docs.docker.com/compose/install/ Allows to easily express the containers to be instantiated at once, and the relations among them Runs the composition on a single machine (i.e., single Docker engine) Use Docker Swarm to deploy containers on multiple nodes 26 Docker Compose We specify how to compose containers in a easy-toread file, by default named docker-compose.yml To start the Docker composition (background -d): $ docker-compose up -d To stop the Docker composition: $ docker-compose down By default, Docker Compose looks for the dockercompose.yml file in the current working directory Change file using -f flag 27

Docker Compose Different versions of the Docker compose file format Latest: version 3 is supported from Docker Compose 1.13 Docker compose file format: https://docs.docker.com/compose/compose-file/ 28 Docker Compose: example Simple Python web app running on Docker Compose Two containers: Python web app and Redis Use Flask framework and maintain a hit counter in Redis See https://docs.docker.com/compose/gettingstarted/ Steps: Write Python app Define Python container image with Dockerfile Define services in docker-compose.yml file Two services: web (image defined by Dockerfile) and redis (image pulled from Docker Hub) Build and run your app with Compose $ docker-compose up d Send HTTP requests using curl (now counter is increased) Stop Compose $ docker-compose down 29

Docker: Swarm mode Docker includes the swarm mode for natively managing a cluster of Docker Engines, which is called swarm See https://docs.docker.com/engine/swarm/ Task: running container part of a swarm service Basic features of swarm mode: Scaling: allows to declare the number of tasks for each service State reconciliation: Swarm monitors the cluster state and reconciles any differences w.r.t. the expressed desired state Multi-host networking: allows to specify an overlay network among services Load balancing: allows to expose the ports for services to an external load balancer. Internally, the swarm lets you specify how to distribute service containers among nodes 30 Docker: Swarm mode A swarm consists of multiple Docker hosts which run in swarm mode Node: an instance of the Docker engine Manager node dispatches tasks to worker nodes Worker nodes receive and execute tasks Load balancing The swarm manager can automatically assign the service a (configurable) PublishedPort External components can access the service on the PublishedPort. All nodes in the swarm route ingress connections to a running task 31

Commands: Swarm cluster Create a swarm: manager node $ docker swarm init --advertise-addr <MANAGER-IP> Swarm initialized: current node (<nodeid>) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token <token> <manager-ip>:port Create a swarm: worker node $ docker swarm join --token <token> <manager-ip>:port Inspect status $ docker info $ docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS <nodeid> * controller Ready Active Leader <nodeid> storage Ready Active 32 Leave the swarm $ docker swarm leave Commands: Swarm cluster If the node is a manager node, you will receive a warning about maintaining the quorum. To override the warning, pass the --force flag After a node leaves the swarm, you can run docker node rm command on a manager node to remove the node from the node list $ docker node rm node-id 33

Commands: manage services Deploy a service to the swarm (from the manager node) $ docker service create -d --replicas 1 \ --name helloworld alpine ping docker.com List running services $ docker service ls ID NAME MODE REPLICAS IMAGE PORTS <serviceid> helloworld replicated 1/1 alpine:latest 34 Commands: manage services Inspect the service $ docker service inspect --pretty <SERVICE-ID> $ docker service ps <SERVICE-ID> ID NAME IMAGE NODE DESIRED ST CURRENT ST ERROR PORTS <cont.id1> helloworld.1 alpine:latest controller Running Running <cont.id2> helloworld.2 alpine:latest storage Running Running Inspect the container $ docker ps <cont.id1> # Manager node CONTAINER ID IMAGE COMMAND CREATED STATUS... NAMES <cont.id1> alpine:latest "ping docker.com" 2 min ago Up 2 min helloworld.1.iuk1sj # Worker node CONTAINER ID IMAGE COMMAND CREATED STATUS... NAMES <cont.id2> alpine:latest "ping docker.com" 2 min ago Up 2 min helloworld.2.skfos4 35

Commands: manage services Scale the service $ docker service scale <SERVICE-ID>=<NUMBER-OF-TASKS> The swarm manager will automatically enact the updates Apply rolling updates to a service $ docker service update --image redis:3.0.7 redis $ docker service update --replicas 2 helloworld Roll back an update $ docker service rollback [OPTIONS] <SERVICE-ID> Remove a service $ docker service rm <SERVICE-ID> 36 Docker Swarm: example Let s use Docker Swarm to scale Python web app on the same host and load balance the traffic among the container replicas See https://docs.docker.com/get-started/part3/ Steps: Define services in docker-compose.yml file Only one service called web Set replication degree to 5 Set resource limits to be used by each single replica Set restart policy to on-failure so that a failed container is automatically restarted Docker supports 4 restart policies» no» on-failure» unless-stopped» always Instruct web s containers to share port 80 via a load-balanced network called webnet Define webnet network (load-balanced overlay network) 37

Start the swarm Docker Swarm: example $ docker swarm init Deploy the stack $ docker stack deploy -c docker-compose.yml getstartedlab Send multiple requests to Python web app and see how they are served by different replicas chosen in a round-robin fashion Take down the app and the swarm $ docker stack rm getstartedlab $ docker swarm leave --force 38