100% found this document useful (1 vote)
75 views

Docker Introduction

The document provides an introduction to Docker containers. It discusses what virtualization and containers are, the benefits of virtualization, and how the Docker architecture works. The key points are: 1) Docker allows building, shipping and running applications by using containers, which package up code and dependencies so applications run reliably from one computing environment to another. 2) The Docker architecture uses containers as virtualization at the operating system level, allowing faster deployment of applications without the overhead of hardware virtualization. 3) Docker images contain the files for a container such as the operating system and application code. Containers run the image and isolate the application's view of the operating system.

Uploaded by

Chandra Shekhar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
75 views

Docker Introduction

The document provides an introduction to Docker containers. It discusses what virtualization and containers are, the benefits of virtualization, and how the Docker architecture works. The key points are: 1) Docker allows building, shipping and running applications by using containers, which package up code and dependencies so applications run reliably from one computing environment to another. 2) The Docker architecture uses containers as virtualization at the operating system level, allowing faster deployment of applications without the overhead of hardware virtualization. 3) Docker images contain the files for a container such as the operating system and application code. Containers run the image and isolate the application's view of the operating system.

Uploaded by

Chandra Shekhar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Docker: Introduction

Jeeva S. Chelladhurai
[email protected]

1
What is Virtualization

• Creating a virtual version


• Computer Hardware
• Operating System
• Storage Device
• Computer Network
• Origin
• 1960s
• Mainframe computers

Source: http://en.wikipedia.org/wiki/Virtualization

2
Types of Hypervisor
• Bare-metal
• Hosted

Bare-Metal Hosted

3
Virtualization

4
Virtualization

5
Virtualization

6
Virtualization!!!
Why? Why?? Why???

7
• Space
• Electricity
• Cooling
• Cabling

8
Benefits of Virtualization

9
Benefits of
Virtualization

10
Benefits of
Virtualization

11
Containers!!!
What heck it is???

12
15
16
Container-Based Virtualization

• Container-based virtualization, also called


operating system virtualization, is an approach
to virtualization in which the virtualization layer
runs as an application within the operating
system (OS). In this approach, the operating
system's kernel runs on the hardware node with
several isolated guest virtual machines (VMs)
installed on top of it. The isolated guests are
called containers.

17
Docker: What?

• Develop, Ship and Run Any Application,


Anywhere
• Open Source Platform
• Eliminate Friction
• Assemble applications from components
• Test and Deploy as fast as possible

18
Docker: Why?

• Faster delivery of your applications


• Separation of duties
• Lightweight and fast
• Deploy and scale more easily
• Run almost everywhere
• Easy to move
• Easy to Scale up and down
• Get higher density and run more workloads
• Faster deployment makes for easier
management

19
Docker: Architecture

Source: https://docs.docker.com/engine/introduction/understanding-docker

20
Docker Architecture
Docker Host
• Client-Server
• Same or Remote
• Socket or RESTful API
• Docker Engine aka

Container 1

Container 2

Container 3

Container 4

Container 5
• Daemon or Server Docker
Client
• Inside Docker
• Image Docker
• Container Engine
• Registry Linux Kernel

21
Type 2 hypervisor vs. Containers

DB App Web Server

Bins/Libs Bins/Libs Bins/Libs

Guest Guest Guest


OS OS OS Web
DB App App
Srv
Hypervisor (Type 2) Cont Othr
Bins/Libs Bins/Libs Mgr App

Host OS Host OS

Hardware Hardware

22
Type 1 hypervisor vs. Containers

DB App Web Server

Bins/Libs Bins/Libs Bins/Libs Web


DB App App
Srv
Guest Guest Guest Cont Othr
OS OS OS Bins/Libs Bins/Libs Mgr App

Hypervisor (Type 1) Host OS

Hardware Hardware

23
Docker: Nuts & Bolts

24
Anatomy of Docker Engine

25
Instructions for hands-on activity

• The hands-on activities would introduce you to various


functionalities of docker and eventually show you how to
run an HTTP service inside a container.
• The sample commands would begin with
$ sudo
Wherein
$ denotes the Linux (UNIX) prompt and the prompt on your
system could be different. So, do not type in $ when try any of
the commands in the subsequent slides
sudo is a Linux (UNIX) command that executes the subsequent
command as root. The docker commands needs root privilege
• Basic knowledge on Linux would be useful

26
Install Docker on Ubuntu

1. Update apt package index


$ sudo apt-get update
2. Add Docker’s official GPG keys
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| sudo apt-key add -
3. Add Docker repo for amd64
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable”
4. Update apt package index again
$ sudo apt-get update
5. Install Docker
$ sudo apt-get install docker-ce

27
Install Docker on CentOS

1. Install yum-utils (for yum-configure-manager utility)


$ sudo yum install -y yum-utils
2. Add Docker CentOs repo
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
3. Update yum package
$ sudo yum makecache fast
4. Install Docker CE
$ sudo yum install docker-ce
5. Start Docker
$ sudo systemctl start docker
28
Installing Docker on Linux

• Linux: Automated Script


$ curl -sSL https://get.docker.io/ | sudo sh
or
$ wget -qO- https://get.docker.io/ | sudo sh

29
Docker for Win/Mac

• Docker for Mac


https://docs.docker.com/docker-for-mac/install/
• Docker for Windows
https://docs.docker.com/docker-for-windows/install/
• Windows & Mac:
https://www.docker.com/toolbox

30
Understand the Docker Setup

Version Check More info


$ docker version $ docker info
Client version: 1.7.0 Containers: 4
Client API version: 1.19 Images: 288
Go version (client): go1.4.2 Storage Driver: aufs
Git commit (client): 0baf609 Root Dir: /data/docker/aufs
OS/Arch (client): linux/amd64 Backing Filesystem: extfs
Server version: 1.7.0 Dirs: 296
Server API version: 1.19 Dirperm1 Supported: false
Go version (server): go1.4.2 Execution Driver: native-0.2
Git commit (server): 0baf609 Logging Driver: json-file
OS/Arch (server): linux/amd64 …. <output truncated> …

31
Docker: Image

• Read-only Layer
• Union File System
• Base Image
• Parent Image
• Image ID
- 64 hexadecimal digit
- Internally 256bit value
- Short ID: 12 hex digit
• Stateless

32
Working with Docker Images

• Downloading Docker Images


$ sudo docker pull busybox

• Verifying Docker Images


$ sudo docker images

• Searching Docker Images


$ sudo docker search mysql

33
Docker Hub

34
Docker: Container

• Adds read-write layer


• Stateful
• Isolates
- Network Interface
- PID Tree
- Mount point
• Container ID
- 64 hexadecimal digit
- Internally 256bit value
- Short ID: 12 hex digit

35
Working with Docker Containers

• Interactive Container
$ sudo docker run -i -t ubuntu:16.04 /bin/bash
root@742718c21816:/# hostname
742718c21816
root@742718c21816:/# id
uid=0(root) gid=0(root) groups=0(root)
root@742718c21816:/# echo $PS1
${debian_chroot:+($debian_chroot)}\u@\h:\w\$
root@742718c21816:/#
Ctrl-p + Ctrl-q.

36
Working with Docker Containers

• Listing the running containers


$ sudo docker ps

• Attaching back to a running containers


$ sudo docker attach <container name or container id>
root@742718c21816:/# pwd
/
root@742718c21816:/usr# exit
exit
$

37
Container Life-Cycle

Source: http://docker-saigon.github.io/post/Docker-Internals/
38
Working with Docker Containers

• Tracking Changes inside Containers


$ sudo docker attach <container name or id>

• Controlling containers
$ sudo docker stop <container name or id>
$ sudo docker start <container name or id>
$ sudo docker restart <container name or id>
$ sudo docker pause <container name or id>
$ sudo docker unpause <container name or id>

39
Hands on Activity: HTTP Service (1/2)

• Hands on activity : Install and run apache2 http service


inside a container.
– NOTE 1: $ denotes your system shell prompt
– NOTE 2: # denotes your containers shell prompt

1. Launch an Ubuntu container in interactive mode


$ sudo docker run -it ubuntu

2. You will land inside the container, inside the container


run apt-get update to sync the apt repo
# apt-get update
3. Install the net-tools (to install ifconfig)
# apt-get install net-tools

40
Hands on Activity: HTTP Service (2/2)

4. Retrieve the container ip address using “ifconfig”


# ifconfig eth0
5. Install apache2
# apt-get install apache2
6. Launch apache2 http service in the foreground
# apache2ctl -D FOREGROUND
7. Connect to the http server by using a web browser on
the same docker host using the container ip address
retrieved earlier

41
Comparing your changes

• Comparing the original image with your changes


$ sudo docker diff <container name or id>
Example:
$ sudo docker diff 42718c21816

42
Creating your own Docker Image

• Preserving your updates


$ sudo docker commit <container name or id> <image name>
Example:
$ sudo docker commit 42718c21816 apache2

43
Inspect

• Inspect a Docker image or container


$ sudo docker inspect <container name/id or image name/id>

44
A few more docker run options

• Run docker as a command


$ sudo docker run ubuntu ls
• Auto-remove container when it is done
$ sudo docker run --rm ubuntu env
• Demonize a container
$ sudo docker run -d ubuntu /bin/bash -c "while true; do date;
sleep 5; done"
• Container logs
$ sudo docker logs <container name or id>

45
Docker Network

• Default
• Bridge
• Host
• Null
• Advanced
• Overlay
• MacVLAN, IPVLAN

46
Default Bridge – docker0

47
Hands On

• Run a Ubuntu Container and get its IP address


- Team will discuss various options and suggest the
best option

48
Filtering the IP address

• sudo docker inspect \


• --format='{{.NetworkSettings.IPAddress}}' <container
id>

49
Container Networking Model

Docker Host

Container Container
lo eth0 lo eth0

veth veth
docker0

eth0

LAN

50
- net none / host

51
Exposing the Containers

• The -p option of docker run


• Has four formats of arguments:
– <hostPort>:<containerPort>
– <containerPort>
– <hostIP>:<hostPort>:<containerPort>
– <hostIP>::<containerPort>
Example:
$ sudo docker run -it -p 80:80 apache2 bash

52
Sharing Host Data

• –v <host path>/<container mount path>


Example:
$ sudo docker run -it -p 80:80 \
-v /host/web:/var/www/html \
apache2 bash

53
Dockerfile
$ cat Dockerfile
# Base image is Ubuntu
FROM ubuntu:16.04

MAINTAINER Jeeva S. Chelladhurai <[email protected]>

# Install apache2 package


RUN apt-get update && \
apt-get install -y apache2 && \
apt-get clean

EXPOSE 80

# Launch apache2 server in the foreground


ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

54
Container as a Service

• Building a Docker image from Dockerfile


$ sudo docker build -t <image name> <directory>
Example:
$ sudo docker build -t apache2 .
• Launch the container as a Service
$ sudo docker run -d -p 80:80 \
-v /host/web:/var/www/html \
apache2

55
Dockerfile Instructions

• FROM • EXPOSE
• MAINTAINER • LABEL
• COPY • RUN
• ADD • CMD
• ENV • ENTRYPOINT
• ARG • HEALTHCHECK
• USER • STOPSIGNAL
• WORKDIR • ONBUILD
• VOLUME • SHELL

56
Linking Container

• Demo linking of two containers


• Explain the pros and cons

57
User-defined Bridge

• Create user-defined bridge


• Explain embedded DNS
• Demonstrate with an example

58
Thank You!

You might also like