CS-580/480 Advanced Topics in Cloud Computing Container III 1
Docker Container https://www.docker.com/ Docker is a platform for developers and sysadmins to develop, deploy, and run applications with containers. Docker is built upon Namespaces and Cgroups (in fact Linux LXC). Written in Go programming language. The use of containers to deploy applications is called containerization. 2
Containerization Containerization is increasingly popular because containers are: Flexible: Even the most complex applications can be containerized. Lightweight: Containers leverage and share the host kernel. Interchangeable: You can deploy updates and upgrades on-the-fly. Portable: You can build locally, deploy to the cloud, and run anywhere. Scalable: You can increase and automatically distribute container replicas. Stackable: You can stack services vertically and on-the-fly. 3
Container Images A container is launched by running an image. An image is an executable package that includes everything needed to run an application(s) -- the application code, a runtime, libraries, environment variables, and configuration files. -- consisting of folders and files just like a file system A container is a runtime instance of an image -- You can see a list of your running containers with the command, 4
Layout of a Docker Container Image A container originates from a base image layer, including a base file system (and applications). When you launch a container, another layer is created on top of the base image layer Container Layer Image Base Layer (e.g., Ubuntu 16.04 file system) 5
Read/Write Permissions The image base is read only The container layer can both read and write A merged view through overlay file system such as AUFS Container Layer Image Base Layer (e.g., Ubuntu 16.04 file system) Read/write Read only https://docs.docker.com/storage/storagedriver/aufs-driver/#how-the-aufs-storage-driver-works 6
Read Policies Reading files: Files only exist in image layer, it is read from image layer Files only exist in container layer, it is read from container layer Files exist in both layer, it is read from container. Files in the container layer obscure files with the same name in the image layer. Container Layer bin new Image Base Layer (e.g., Ubuntu 16.04 file system) 7
Writing Polices Writing files: Writing to a file for the first time (the file exists in the image layer) --- copy_up: copy files from the base layer to the container layer, and write changes to it. Container Layer bin Image Base Layer (e.g., Ubuntu 16.04 file system) 8
How container reads and writes work with Writing files: Writing to a file for the first time --- copy_up: copy files from the base layer to the container layer, and write changes to it. Deleting a file a whiteout file is created in the container layer marking that the file with the same name in the image layer is invalid Container Layer Image Base Layer (e.g., Ubuntu 16.04 file system) 9
Pros/Cons of Overlay file systems Cons Overhead Pros Many container instances share the same base images Saving space Container image can be stackable Easy to build new images 10
Stackable Container Images MySQL Server (Container Layer) MySQL Server (Image Layer 2) Apache Server (Container Layer) Apache Server (Image Layer 1) Apache Server (Image Layer 1) Ubuntu 16.04 (Image Layer 0) Ubuntu 16.04 (Image Layer 0) Ubuntu 16.04 (Image Layer 0) 11
Demo Time Get a Docker container image: docker image pull image_name (e.g., ubuntu) Images are stored How many layers are there? /var/lib/docker/aufs/layers What kinds of files are contained /var/lib/docker/aufs/diff May be different depending on which storage drive you are using Run a container from an image docker run ubuntu command e.g., docker run ubuntu echo Hello World! 12
Demo Time Run docker container in detached mode & attach docker run -id ubuntu /bin/bash docker attach container_id Run docker container in attached mode docker run -it ubuntu /bin/bash 13
Demo Time All layers will be put under /var/lib/docker/aufs/diff Including both base image files and container layers A container s file system will be put under /var/lib/docker/aufs/mnt The merged view (from both images and container layers) 14
Demo Time You can publish your containers docker login docker commit container_id repository_address/image_name docker push repository_address/image_name 15
Docker Architecture 16
Micro-services vs. Containers Micro-services VM1 Web Servers + Bussiness Logic + Database Servers Design Pattern s1 s3 s2 s4 VM2 s5 Applications Infrastructure VM3 17
Container Orchestration Micro-services s1 s2 VM1 Web Servers + Bussiness Logic + Database Servers Design Pattern s1 s3 s2 s4 Container Orchestration s1 s2 s3 VM2 s5 s4 s5 Applications Infrastructure VM3 18
19
ubernetes A platform for hosting Docker containers in a clustered environment with multiple Docker hosts Providing orchestrating features: grouping, load balancing, auto-healing, and scaling. Started by Google Other similar projects Docker swarm, Apache Mesos 20
Basics of ubernetes Cluster Service 21
Basics of ubernetes API Cluster Service 22
Basics of ubernetes API Cluster Service 23
Basics of ubernetes API Cluster Service 24
Basics of ubernetes YAML Configuration Files s Pod_1: -- container image1 -- container image2 Replicas: 3 Pod_2: -- container image3 -- container image4 Replicas: 2 API Cluster Service s s s 25
Basics of ubernetes YAML Configuration Files Pod1 Replica1 Pod_1: -- container image1 -- container image2 Replicas: 3 Pod_2: -- container image3 -- container image4 Replicas: 2 API Cluster Service Pod1 Replica2 Pod1 Replica3 Pod2 Replica1 Pod2 Replica2 26
Basics of ubernetes YAML Configuration Files Pod1 Replica1 Pod_1: -- container image1 -- container image2 Replicas: 3 Pod_2: -- container image3 -- container image4 Replicas: 2 API Cluster Service Pod1 Replica2 Pod1 Replica3 Pod2 Replica1 Pod2 Replica2 27
Basics of ubernetes YAML Configuration Files Pod_1: -- container image1 -- container image2 Replicas: 3 Pod_2: -- container image3 -- container image4 Replicas: 2 API Cluster Service Pod1 Replica1 s Pod2 Replica1 Pod1 Replica2 s Pod1 Replica3 s Pod2 Replica2 s 28
https://github.com/kubernetes/kubernetes ubernetes Mores YAML Configuration Files Pod1 Replica1 s Pod_1: -- container image1 -- container image2 Replicas: 3 Load balancing API Cluster Service Pod1 Replica2 s Pod1 Replica3 s s 29
https://github.com/kubernetes/kubernetes ubernetes Mores YAML Configuration Files Pod1 Replica1 Pod_1: -- container image1 -- container image2 Replicas: auto-scaling Load balancing API Cluster Service Pod1 Replica2 Pod1 Replica3 Pod1 Replica4 30
References https://www.cio.com/article/2924995/software/what-are-containersand-why-do-you-need-them.html Linux Namespace: https://www.cs.ucsb.edu/~rich/class/cs293bcloud/papers/lxc-namespace.pdf Docker FS Overlay https://docs.docker.com/storage/storagedriver/overlayfsdriver/#modifying-files-or-directories 31