Download presentation
Presentation is loading. Please wait.
1
Docker in Action
2
HELLO! I am Sanjeewa Alwis I am here because I love cloud technology.
You can find me on linkedin,
3
Cargo Transport 1960 Do I worry about how goods interact (e.g. coffee beans next to spices) Multiplicity of Goods Can I transport quickly and smoothly (e.g. from boat to train to truck) Multipilicity of methods for transporting/storing
4
Solution: Intermodal Shipping Container
A standard container that is loaded with virtually any goods, and stays sealed until it reaches final delivery. Do I worry about how goods interact (e.g. coffee beans next to spices) Multiplicity of Goods …in between, can be loaded and unloaded, stacked, transported efficiently over long distances, and transferred from one mode of transport to another Multiplicity of methods for transporting/storing Can I transport quickly and smoothly (e.g. from boat to train to truck)
5
The Challenge Do services and apps interact appropriately?
Multiplicity of Stacks User DB Static website postgresql + pgv8 + v8 Queue Analytics DB nginx modsecurity + openssl + bootstrap 2 Redis + redis-sentinel hadoop + hive + thrift + OpenJDK Web frontend Background workers Ruby + Rails + sass + Unicorn Python celery + pyredis + libcurl + ffmpeg + libopencv + nodejs + phantomjs API endpoint Python Flask + pyredis + celery + psycopg + postgresql-client Production Cluster Development VM Public Cloud Can I migrate smoothly and quickly? QA server Disaster recovery Customer Data Center Contributor’s laptop Production Servers
6
Docker is a shipping container system for code
Static website Analytics DB User DB Web frontend Queue Do services and apps interact appropriately? Multiplicity of Stacks An engine that enables any payload to be encapsulated as a lightweight, portable, self-sufficient container… …that can be manipulated using standard operations and run consistently on virtually any hardware platform Multiplicity of hardware environments Can I migrate smoothly and quickly Development VM QA server Customer Data Center Public Cloud Production Cluster Contributor’s laptop
7
Why Developers Love Docker?
Build once run anywhere A clean, safe, portable runtime environment for app. No concerns around missing dependencies, packages and other pain points during subsequent deployments. Run each app in its own isolated container, so he or she can run various versions of libraries and other dependencies for each app without worrying Automate testing, integration, packaging…anything you can script Reduce/eliminate concerns about compatibility on different platforms, either your own or your customers.
8
Why Devops Cares? Configure once run anything
Make the entire lifecycle more efficient, consistent, and repeatable Eliminate inconsistencies between development, test, production, and customer environments Support segregation of duties Significantly improves the speed and reliability of continuous deployment and continuous integration systems Because the containers are so lightweight, address significant performance, costs, deployment, and portability issues normally associated with VMs
9
Why it works—Separation of Focus
Developer Focus on what’s “inside” the container code Libraries Package Manager Apps Data All Linux servers look the same Ops Guy Focus what’s “outside” the container Logging Remote access Monitoring Network config All containers start, stop, copy, attach, migrate, etc. the same way
10
Containers vs. VMs Containers are isolated, but share OS and, where
App A App A’ App B Containers are isolated, but share OS and, where appropriate, bins/libraries Bins/ Libs Bins/ Libs Bins/ Libs VM Guest OS …result is significantly faster deployment, much less overhead, easier migration, faster restart Guest OS Guest OS Guest OS Guest OS App A App A’ App B App B’ App B’ App B’ Container Docker Hypervisor (Type 2) Bins/Libs Bins/Libs Host OS Host OS Server Server
11
Why are Docker containers lightweight?
VMs Containers App A App A App A’ App A App A App Δ Bins/ Libs Bins/ Libs Bins/ Libs Bins/ Libs Bins/ Guest OS Guest OS Guest OS Guest OS Original App (No OS to take up space, resources, or require restart) Copy of App No OS. Can Share bins/libs Modified App Copy on write capabilities allow us to only save the diffs Between container A and container A’ VMs Every app, every copy of an app, and every slight modification of the app requires a new virtual server
12
What are the basics of the Docker system?
Container Image Registry Push Step 3 Container A Search Pull Pull Base image Step 2 Build Step 1 Source Code Repository Run Dockerfile For A Docker Container A Container B Container C Docker Engine Host 1 OS (Linux) Host 2 OS (Linux)
13
Changes and Updates Docker Container Image Registry App A Push App Δ
Bins/ Libs Bins/ Base Container Image Container Mod A’ Container Mod A’’ App Δ Update Bins/ App A App A’’ Bins/ Libs Bins/ Libs Bins/ Docker Engine Docker Engine Host running A wants to upgrade to A’’. Requests update. Gets only diffs Host is now running A’’
14
What is Docker Engine? Docker Engine is a client-server application with these major components: A server which is a type of long-running program called a daemon process. A REST API which specifies interfaces that programs can use to talk to the daemon and instruct it what to do. A command line interface (CLI) client.
15
Hands-on Session
16
HELLO! I am Kasun Geethaka
17
Installing Docker Linux (Natively support) : Windows: Windows 10: Early versions: Mac:
18
Using the Docker Toolbox
The Docker Toolbox installs the following components: • VirtualBox + Boot2Docker VM image (runs Docker Engine) • Kitematic GUI • Docker CLI • Docker Machine • Docker Compose
19
About boot2docker It is a very small VM image (~30 MB) It runs on most hypervisors and can also boot on actual hardware
20
Hello World In your Docker environment just run the following command: $ docker run busybox echo hello world
21
A more useful container
Let's run a more exciting container: $ docker run -it ubuntu This is a brand new container. It runs a bare-bones, no-frills ubuntu system. -it is shorthand for -i -t. -i tells Docker to connect us to the container's stdin. -t tells Docker that we want a pseudo-terminal $ docker run –it -d ubuntu
22
Connecting to a demonized container docker attach <conatinerID>/<name> Ctrl+P+Q to detache docker exec –it <conatinerID/name> bin/bash
23
Do something in our container
Try to run figlet in our container figlet hello bash figlet command not found Alright, we need to install it. apt-get update apt-get install figlet Are these changes retain in docker image ????
24
Inspect the changes Now let's run docker diff to see the difference between the base image and our container $ docker diff <conatinerID/name>
25
How to save changes to containers ?
docker commit • Saves all the changes made to a container into a new layer. • Creates a new image (effectively a copy of the container) docker build • Performs a repeatable build sequence. • This is the preferred method!
26
Writing our first Dockerfile
Our Dockerfile must be in a new, empty directory. 1. Create a directory to hold our Dockerfile. $ mkdir myimage 2. Create a Dockerfile inside this directory. $ cd myimage $ vim Dockerfile FROM ubuntu RUN apt-get update RUN apt-get install figlet docker build -t figlet .
27
Copying files during the build
We want to build a container that compiles a basic "Hello world" program in C. Here is the program, hello.c: int main () { puts("Hello, world!"); return 0; } Let's create a new directory, and put this file in there. Then we will write the Dockerfile.
28
On Debian and Ubuntu, the package build-essential will get us a compiler. When installing it, don't forget to specify the -y flag, otherwise the build will fail (since the build cannot be interactive). Then we will use COPY to place the source file into the container. FROM ubuntu RUN apt-get update RUN apt-get install -y build-essential COPY hello.c / RUN make hello CMD /hello Create this Dockerfile
29
Persisted snapshot that can be run
Terminology - Image Persisted snapshot that can be run images: List all local images run: Create a container from an image and execute a command in it tag: Tag an image pull: Download image from repository search: Search for images in Docker repository rmi: Delete a local image This will also remove intermediate images if no longer used
30
Terminology - Container
Runnable instance of an image ps: List all running containers ps –a: List all containers (incl. stopped) top: Display processes of a container start: Start a stopped container stop: Stop a running container pause: Pause all processes within a container rm: Delete a container commit: Create an image from a container
31
View the logs of a container
$ docker run -d jpetazzo/clock Just like with the standard UNIX command tail -f, we can follow the logs of our container: $ docker logs --tail 1 –follow <containerID/name>
32
Inspecting a container
The docker inspect command will output a very detailed JSON map $ docker inspect <containerID> [{ "AppArmorProfile": "", "Args": [], "Config": { "AttachStderr": true, "AttachStdin": false, "AttachStdout": true, "Cmd": [ "bash" ], "CpuShares": 0, ...
33
Manual allocation of port numbers
If you want to set port numbers yourself: $ docker run -d -p 80:80 nginx $ docker run -d -p 8000:80 nginx We are running two NGINX web servers. The first one is exposed on port 80. The second one is exposed on port Note: the convention is port-on-host:port-on-container.
34
Mounting Volumes using the -v flag you can mount a directory from your Docker engine’s host into a container $ docker run -v src:/website_files -d -p 80:80 kitematic/hello-world-nginx
35
Connecting multiple containers together
docker run -d -P --link=redis:redis jpetazzo/trainingwheels docker run --name redis -d -p 6379:6379 redis
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.