SlideShare uma empresa Scribd logo
1 de 104
Making “Elephants” Dance
Runcy
OommenSlides: http://codeops.tech
What is Docker?
Docker is an open-source project that automates the deployment of
applications inside software containers.
What is Docker?
“an open platform for developers and sysadmins to build, ship, and run
distributed applications”
Why Docker?
Why Docker?
“Docker containers wrap a piece of software in a complete
filesystem that contains everything needed to run: code,
runtime, system tools, system libraries – anything that can
be installed on a server. This guarantees that the software
will always run the same, regardless of its environment.”
source: https://www.docker.com/what-docker
Why Docker?
VMs vs. Docker
VMs vs. Docker
Docker accesses virtualisation features of
Linux
Getting Started
Essential Docker components
Can I install Docker from
commandline?
Yes! from get.docker.com
Finding Docker version
$ docker version
Finding details of a Docker
installation
$ docker info
How to do “hello world” in
Docker?
$ docker run docker/whalesay cowsay Hello World
How to do “Hello World” in
Docker?
$ docker run docker/whalesay cowsay "Hello world"
Runs a command
in a new container
Base image for
creating the container
Command name to
run within the container
Argument to the
“cowsay” command
How to do “hello world” in
Docker?
$ docker run -it hello-world
How to get help on commands to
use?
$ docker --help
Docker commands look like Linux commands - so
familiarity with Linux commands can really help to get
up to speed quickly with Docker.
Docker Images
“Images are blueprints for containers”
How to get list of images?
$ docker images
How to search for an image?
$ docker search <image_name>
How to get an image?
$ docker pull <image_name>
In my case fedora image was
already pulled. If it were not there,
Docker would have pulled it afresh
Choose smaller images
❖ Example: Alpine vs. Fedora (5 MB vs. 205 MB)
alpine latest 4e38e38c8ce0 4 weeks ago 4.799 MB
fedora latest f9873d530588 4 weeks ago 204.4 MB
❖ Prefer choosing a smaller base image that provides
equivalent functionality (for your requirement) instead of
choosing a larger one
How to get details of an
image?
$ docker inspect <image_name>
How to see “layers” in an image?
$ docker history <image_name>
Each of these lines are layers and
the size column shows the exact size
of each layer in the image
How can I load and store
images?
$ docker save <image_name> -o <filename.tar>
$ docker load –i <filename.tar>
How do I delete an image?
$ docker rmi <image-tag>
How to delete all docker images?
$ docker rmi $(docker images -q)
docker images -q
lists all image ids
❖ Avoid “Image Sprawl”
❖ Remove unused images and release disk
space
How to find “dangling
images”?
$ docker images -f "dangling=true"
❖ Remove “dangling images” using the command below:
$ docker rmi $(docker images -f "dangling=true" -q)
Docker Containers
How to get list of containers?
$ docker ps -a
How to run a container?
$ docker run OPTIONS <image-tag> CMD ARGS
$ docker run fedora /bin/echo 'Hello world'
Image name Command argument
Command name
How to run a container
interactively?
$ docker run –i -t fedora /bin/bash
Interactive
Run in terminal
Cobb’s Totem - The Top
Running a container - Totem?
How to run a container in the
background?
$ docker run -d alpine /bin/sh -c "while true; do echo current date and time is: $(date); sleep 10; done"
Detach
How to expose/map a port?
$ docker inspect c7ada3308269 | grep Port
$ docker run –d –p 80:80 nginx
Mapped port - nginx
host port (on which this command is run)
Using Nginx
Type http://localhost:80 in your browser window
How to expose a port?
$ docker run -d -p 80 --name mynginx
nginx
$ docker inspect mynginx | grep
Port
randomly assigned and mapped
port number (by docker)
host port; since no explicit mapped
port is provided, a random port is
assigned
How to expose all exposed
ports?
$ docker run -d -P --name mynginx
nginx
$ docker port
mynginx
-P publishes all exposed ports to random ports
Exposing ports
$ docker run -d -p 80 --name nginx1 nginx
d415758906dccc07aae319fc438c825e878ea00ffd58551c63d5c41fd39e4153
$ docker port nginx1
80/tcp -> 0.0.0.0:32769
Maps the port 80 from
container to a random port in
the host
$ docker run -d -p 80:80 --name nginx2 nginx
4d7c26218b440d054d33799b7be1174254db50550254211d739f9403ca4092e9
$ docker port nginx2
80/tcp -> 0.0.0.0:80
Maps the port 80 from
container to port 80 in the host
$ docker run -d -p 80:80 -p 443:443 --name nginx3 nginx
2cfde425380601479aaf5e33a9b1fc09111d84b49595c33f509c00ad2cafc12d
$ docker port nginx3
80/tcp -> 0.0.0.0:80
443/tcp -> 0.0.0.0:443
Maps the container ports 80
and 443 to the same port nos.
in the host
$ docker run -d -P --name nginx4 nginx
8e5fadfbcf5f3145909aed3219738535ad81e534153d5958fbec07f9e9c49e67
$ docker port nginx4
443/tcp -> 0.0.0.0:32770
80/tcp -> 0.0.0.0:32771
Maps the container ports 80
and 443 to random port nos. in
the host
The exposed ports in “nginx:latest” are “443/tcp" and “80/tcp”
How to attach to a running
container?
$ docker attach <container_id>
$ docker run –d ubuntu /bin/sh -c "while true; do echo current date and time is: $(date); sleep 10; done"
short for “—detach” and it runs
container in the background
The “attach” command attaches to a running container
How to detach from a running container (without
exiting)?
From docker documentation
# To detach the tty without exiting the shell,
# use the escape sequence Ctrl-p + Ctrl-q
How to get list of containers?
$ docker ps
How do I see all the
containers?
$ docker ps -a
Explicitly remove exited
containers
❖ Explicitly use "rm" to remove the container from the file
system - otherwise, even if the container exits, it is not
cleaned up yet (and will hog memory).
How do I remove a container?
$ docker stop <container_id>
You have to first stop a
container before trying
to remove it
$ docker rm <container_id>
How to remove all the
containers?
$ docker stop $(docker ps -a -q)
$ docker rm $(docker ps -a –q)
Note how the output
shows no containers
How to debug on a running
container?
$ docker exec –it <container_id> <cmd>
Using nginx
Nginx exposes ports 80; -P maps them
randomly in the custom ports range
$ docker run –d –name mynginx –P nginx
Using nginx - Example
$ cat Dockerfile
FROM nginx:latest
MAINTAINER Runcy Oommen
ADD ./index.html /usr/share/nginx/html/index.html
EXPOSE 80
$ cat index.html
<h1> welcome to Dockerizing apps! <h1>
$ docker build .
Sending build context to Docker daemon 3.072 kB
// output cropped ...
Removing intermediate container b043a75a4e1c
Successfully built 1aae04309f8b
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 1aae04309f8b 6 seconds ago 182.8 MB
$ docker run -p 80:80 -d 1aae04309f8b
984c179231188445289e70d854250e4e981b77a899208360db4466e73930be42
$ curl localhost:80
<h1> welcome to Dockerizing apps! <h1>
Type “localhost:80” in
the browser address bar
How do I run a C program?
$ cat Dockerfile
FROM gcc:latest
MAINTAINER Runcy Oommen version: 0.1
COPY . /usr/src/mycapp
WORKDIR /usr/src/mycapp
RUN gcc -o first first.c
CMD ["./first"]
$ cat first.c
#include <stdio.h>
int main() { printf("hello worldn"); }
$ docker build . –t "mycapp:latest"
Sending build context to Docker daemon 3.072
kB
Step 1 : FROM gcc:latest
---> a0b516dc1799
// .. steps cropped...
Successfully built f99e7f18fa42
$ docker run -it mycapp
hello world
How do I run a Java
program?$ cat Dockerfile
FROM java:latest
COPY . /usr/src/
WORKDIR /usr/src/
RUN javac hello.java
CMD ["java", "hello"]
$ cat hello.java
class hello {
public static void main(String []args) {
System.out.println("hello world");
}
}
$ docker build . –t "myjavaapp:latest"
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM java:latest
---> 264282a59a95
// intermediate steps cropped
Successfully built 0d7a3a12ba9d
$ docker run myjavaapp
hello world
Beware of “container
sprawl”
❖ Application broken to run in “too many containers“ can be
difficult to deal with!
“Breaking deployments into more functional discrete
parts is smart, but that means we have MORE
PARTS to manage. There's an inflection point
between separation of concerns and sprawl.”
-- Rob Hirschfeld
(OpenStack Foundation board member)
Building images using
Dockerfile
Different ways to create
images
docker commit Build an image from a container
docker build
Create an image from a Dockerfile by executing the
build steps given in the file
docker import
Create a base image by importing from a tarball.
[import is mainly used for creating base-images; first
two options are widely used]
Dockerfile - key instructions
FROM
The base image for building the new docker image; provide “FROM scratch” if
it is a base image itself
MAINTAINER The author of the Dockerfile and the email
RUN Any OS command to build the image
CMD
Specify the command to be started when the container is run; can be
overridden by the explicit argument when providing docker run command
ADD Copies files or directories from the host to the container in the given path
EXPOSE Exposes the specified port to the host machine
Docker Volumes
Docker volume commands
Command Description
docker volume create Create a volume
docker volume inspect
Display detailed information on one
or more volumes
docker volume ls List the available volumes
docker volume rm Remove one or more volumes
Commands for Docker
volumes
$ docker volume create --name myvolume
myvolume
$ docker volume ls
local myvolume
$ docker volume inspect myvolume
[
{
"Name": "myvolume",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/myvolume/_data",
"Labels": {},
"Scope": "local"
}
]
$ docker volume rm myvolume
myvolume
How to persist data?
$ docker run -v /volumetesting --name="persistdata" alpine /bin/sh -c "echo testing
persistence with volumes > /volumetesting/textfile.txt”
$ docker run --volumes-from=persistdata alpine /bin/sh -c "cat /volumetesting/textfile.txt"
testing persistence with volumes
Use -v option to “mount volumes”
Removing volumes
$ docker volume rm <volume_name>
Removing containers with
volumes
❖ When the container is removed, the volumes will not be
removed. If the volumes also need to be removed, you
have to use the -v option
$ docker rm –v <sha256_hash>
Clean up volumes
❖ You can “clean up” the volumes if you aren't using them.
$ docker volume rm $(docker volume ls -q)
Docker Compose
docker-compose commands
Command Description
docker-compose up (Re)build services
docker-compose kill Kill the containers
docker-compose logs Show the logs of the containers
docker-compose down
Stop and remove images, containers, volumes
and networks
docker-compose rm Remove stopped containers
Creating multiple Docker
containers
Step 1. Create a docker-compose.yml file
Step 2. Execute “docker-compose up -d”
Step 3. Execute “docker-compose logs” from another shell (but from same dir)
Step 4. Execute “docker-compose down”
Docker Networking
Getting the ip address of a
container
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' fervent_sinoussi
172.17.0.6
$ docker attach fervent_sinoussi
root@856aed6a92f1:/# ip addr
// ...
92: eth0@if93: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:06 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.6/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:6/64 scope link
valid_lft forever preferred_lft forever
root@856aed6a92f1:/# cat /etc/hosts
// ...
172.17.0.6 856aed6a92f1
root@856aed6a92f1:/#
There are many ways to get the IP address of a container:
1. Use the docker inspect command
2. Use ip addr command from the container’s shell
3. Use “cat /etc/hosts” and check the entry for the container
How to get port mappings of a
container?
$ docker port <container_id>
Three kinds of networks
$ docker network ls
By default, containers are
added to the bridge network.
You can see the containers in
bridge network here
Docker network commands
Command Description
docker network connect Connect a container to a network
docker network create Create a network
docker network disconnect
Disconnect a container from a
network
docker network inspect
Display detailed information on one
or more networks
docker network ls List networks
docker network rm Remove one or more networks
Docker security
Docker security
“One primary risk with running Docker containers is that the default
set of capabilities and mounts given to a container may provide
incomplete isolation, either independently, or when used in
combination with kernel vulnerabilities”
Source: https://docs.docker.com/engine/security/security/
Docker workbench for
security
git clone https://github.com/docker/docker-bench-security.git
cd docker-bench-security
sh docker-bench-security.sh
git clone https://github.com/docker/docker-bench-security.git
cd docker-bench-security
docker-compose run --rm docker-bench-security
OR
❖ Use the free Docker Workbench For Security to check for
violations of security best practices
Docker workbench for
security
Monitoring Docker
Stats for all running
containers
$ docker stats
Displays resource utilisation (cpu,
memory, etc) details; automatically
updated when details change
Stats for a specific Docker
$ docker stats <CONTAINTER_ID>
Other Topics
‘RunC’ container runtime
RunC is the name of the container runtime used by Docker
It is part of OCI (Open Container Initiative)
https://runc.io/
Can I use GUI instead of command-
line?
Use “kitematic” (https://github.com/docker/kitematic)
Crazy stuff: Docker in
Docker!!
$ docker run --privileged -d docker:dind"
“docker:dind” is the official “Docker In Docker image”
See: https://github.com/jpetazzo/dind
Myths and Misconceptions
Docker *completely* replaces
VMs
Containers AND VMs
Docker is *completely*
portable
There are limitations to portability with Docker (depending on
what you mean by “portable”).
For example, you can run a Windows Docker container only on
Windows and run a Linux Docker container only on Linux (and
not vice versa).
Build once, run anywhere - but conditions apply!
“Management says we need
Docker, so let’s use it”
Quick Ref
Docker commands
Docker commands
Source: http://zeroturnaround.com/wp-content/uploads/2016/03/Docker-cheat-sheet-by-RebelLabs.png
Where to learn more?
Relevant URLs
❖ Docker resources list: https://github.com/hangyan/docker-resources
❖ Self-learning courses: https://training.docker.com/
❖ Detailed documentation: https://docs.docker.com/
❖ Various presentations: http://container.training
❖ SE-Radio Episode 217: James Turnbull on Docker
DOCKER: UP &
RUNNING➤ Covers how to develop, test,
debug, ship, scale, and
support with Docker from
DevOps perspective
➤ We liked the useful tips;
examples:
➤ “Maximize robustness with fast
startup and graceful shutdown.”
➤ “Explicitly declare and isolate
dependencies.”
➤ “Strictly separate build and run
stages.”
http://amzn.com/1491917571
“Docker: Up & Running”, Karl Matthias, Sean P. Kane, O'Reilly Media; 1 edition (July 3, 2015)
THE DOCKER
BOOK➤ Interesting sub-title:
“Containerization is the new
virtualization”.
➤ From James Turnbull (CTO at
Kickstarter and Advisor at
Docker)
➤ Useful to get comfortable with
core concepts of Docker
➤ Useful for developers,
operations staff (and DevOps),
and SysAdmins
➤ Supporting website:
http://dockerbook.com/
http://www.amazon.in/dp/B00LRROTI4
The Docker Book, James Turnbull, Amazon Digital South Asia Services, July 2014
DOCKER
COOKBOOK➤ Contents written in recipe
format (Problem, Solution,
Discussion)
➤ Useful because we can look for
solutions to the problems that we
face when using Docker
➤ What we like: it covers topics
that are not covered well in
other books including
Kubernetes, Docker
ecosystem tools, monitoring
Docker, and application use
cases (CI, CD)
http://amzn.com/149191971X
“Docker Cookbook”, Sébastien Goasguen, O'Reilly Media, 2015
❖ Book organized into
three parts:
❖ Background and Basics
❖ The Software Lifecycle with
Docker
❖ Tools and Techniques
❖ Useful example: Walks
you through the steps to
develop and deploy web
applications with Docker
❖ Though the book
touches upon basics, it
covers more advanced
topicshttp://amzn.com/1491915765
Using Docker: Developing and Deploying Software with Containers, Adrian Mouat, O'Reilly Media, 2016
USING
DOCKER
Meetups
http://www.meetup.com/Container-Developers-Meetup-Bangalore/
http://www.meetup.com/CloudOps-Meetup-Bangalore/
http://www.meetup.com/Bangalore-SDN-IoT-NetworkVirtualization-Enthusiasts/
http://www.meetup.com/SoftwareArchitectsBangalore/
THANK YOU!
Q &
A

Mais conteúdo relacionado

Mais procurados

Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
John Willis
 
Docker Introduction + what is new in 0.9
Docker Introduction + what is new in 0.9 Docker Introduction + what is new in 0.9
Docker Introduction + what is new in 0.9
Jérôme Petazzoni
 

Mais procurados (20)

Introduction To Docker
Introduction To DockerIntroduction To Docker
Introduction To Docker
 
Docker and Containers for Development and Deployment — SCALE12X
Docker and Containers for Development and Deployment — SCALE12XDocker and Containers for Development and Deployment — SCALE12X
Docker and Containers for Development and Deployment — SCALE12X
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
 
Architecting .NET Applications for Docker and Container Based Deployments
Architecting .NET Applications for Docker and Container Based DeploymentsArchitecting .NET Applications for Docker and Container Based Deployments
Architecting .NET Applications for Docker and Container Based Deployments
 
Introduction to Docker and deployment and Azure
Introduction to Docker and deployment and AzureIntroduction to Docker and deployment and Azure
Introduction to Docker and deployment and Azure
 
Introducing Docker
Introducing DockerIntroducing Docker
Introducing Docker
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Docker
DockerDocker
Docker
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
 
Learning Docker with Thomas
Learning Docker with ThomasLearning Docker with Thomas
Learning Docker with Thomas
 
Learn docker in 90 minutes
Learn docker in 90 minutesLearn docker in 90 minutes
Learn docker in 90 minutes
 
docker installation and basics
docker installation and basicsdocker installation and basics
docker installation and basics
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Docker Presentation at the OpenStack Austin Meetup | 2013-09-12
Docker Presentation at the OpenStack Austin Meetup | 2013-09-12Docker Presentation at the OpenStack Austin Meetup | 2013-09-12
Docker Presentation at the OpenStack Austin Meetup | 2013-09-12
 
Devoxx France 2015 - The Docker Orchestration Ecosystem on Azure
Devoxx France 2015 - The Docker Orchestration Ecosystem on AzureDevoxx France 2015 - The Docker Orchestration Ecosystem on Azure
Devoxx France 2015 - The Docker Orchestration Ecosystem on Azure
 
Docker 101: An Introduction
Docker 101: An IntroductionDocker 101: An Introduction
Docker 101: An Introduction
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
Docker 101 - Intro to Docker
Docker 101 - Intro to DockerDocker 101 - Intro to Docker
Docker 101 - Intro to Docker
 
Docker Introduction + what is new in 0.9
Docker Introduction + what is new in 0.9 Docker Introduction + what is new in 0.9
Docker Introduction + what is new in 0.9
 

Semelhante a Docker Introductory workshop

Docker workshop
Docker workshopDocker workshop
Docker workshop
Evans Ye
 

Semelhante a Docker Introductory workshop (20)

Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)
 
Docker workshop
Docker workshopDocker workshop
Docker workshop
 
Primi passi con Docker - ItalianCoders - 12-01-2021
Primi passi con Docker - ItalianCoders - 12-01-2021Primi passi con Docker - ItalianCoders - 12-01-2021
Primi passi con Docker - ItalianCoders - 12-01-2021
 
Running the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker ContainerRunning the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker Container
 
Docker Command Line, Using and Choosing containers
Docker Command Line, Using and Choosing containers Docker Command Line, Using and Choosing containers
Docker Command Line, Using and Choosing containers
 
Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020
 
JDO 2019: Tips and Tricks from Docker Captain - Łukasz Lach
JDO 2019: Tips and Tricks from Docker Captain - Łukasz LachJDO 2019: Tips and Tricks from Docker Captain - Łukasz Lach
JDO 2019: Tips and Tricks from Docker Captain - Łukasz Lach
 
Introduction to Docker - Learning containerization XP conference 2016
Introduction to Docker - Learning containerization  XP conference 2016Introduction to Docker - Learning containerization  XP conference 2016
Introduction to Docker - Learning containerization XP conference 2016
 
Docker
DockerDocker
Docker
 
Docker for mere mortals
Docker for mere mortalsDocker for mere mortals
Docker for mere mortals
 
Docker in Action
Docker in ActionDocker in Action
Docker in Action
 
Docker, Kubernetes, and Google Cloud
Docker, Kubernetes, and Google CloudDocker, Kubernetes, and Google Cloud
Docker, Kubernetes, and Google Cloud
 
Docker
DockerDocker
Docker
 
Deploying .net core apps to Docker - dotnetConf Local Bengaluru
Deploying .net core apps to Docker - dotnetConf Local BengaluruDeploying .net core apps to Docker - dotnetConf Local Bengaluru
Deploying .net core apps to Docker - dotnetConf Local Bengaluru
 
Docker workshop DevOpsDays Amsterdam 2014
Docker workshop DevOpsDays Amsterdam 2014Docker workshop DevOpsDays Amsterdam 2014
Docker workshop DevOpsDays Amsterdam 2014
 
Docker From Scratch
Docker From ScratchDocker From Scratch
Docker From Scratch
 
Docker: A New Way to Turbocharging Your Apps Development
Docker: A New Way to Turbocharging Your Apps DevelopmentDocker: A New Way to Turbocharging Your Apps Development
Docker: A New Way to Turbocharging Your Apps Development
 
How to _docker
How to _dockerHow to _docker
How to _docker
 
Docker Starter Pack
Docker Starter PackDocker Starter Pack
Docker Starter Pack
 
Docker - from development to production (PHPNW 2017-09-05)
Docker - from development to production (PHPNW 2017-09-05)Docker - from development to production (PHPNW 2017-09-05)
Docker - from development to production (PHPNW 2017-09-05)
 

Mais de Runcy Oommen

Mais de Runcy Oommen (20)

Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
Security enhancements for popular GCP services
Security enhancements for popular GCP servicesSecurity enhancements for popular GCP services
Security enhancements for popular GCP services
 
Designing A Platform Agnostic HA System
Designing A Platform Agnostic HA SystemDesigning A Platform Agnostic HA System
Designing A Platform Agnostic HA System
 
Security for cloud native workloads
Security for cloud native workloadsSecurity for cloud native workloads
Security for cloud native workloads
 
Serverless solution architecture in AWS
Serverless solution architecture in AWSServerless solution architecture in AWS
Serverless solution architecture in AWS
 
Europe Cloud Summit - Security hardening of public cloud services
Europe Cloud Summit - Security hardening of public cloud servicesEurope Cloud Summit - Security hardening of public cloud services
Europe Cloud Summit - Security hardening of public cloud services
 
Cloud & GCP 101
Cloud & GCP 101Cloud & GCP 101
Cloud & GCP 101
 
Serverless security for multi cloud workloads
Serverless security for multi cloud workloadsServerless security for multi cloud workloads
Serverless security for multi cloud workloads
 
Building AWS native serverless website
Building AWS native serverless websiteBuilding AWS native serverless website
Building AWS native serverless website
 
Security hardening of core AWS services
Security hardening of core AWS servicesSecurity hardening of core AWS services
Security hardening of core AWS services
 
Get to know Git
Get to know GitGet to know Git
Get to know Git
 
GCDC Bengaluru - Community Growth Hacking
GCDC Bengaluru - Community Growth HackingGCDC Bengaluru - Community Growth Hacking
GCDC Bengaluru - Community Growth Hacking
 
Earth Engine on Google Cloud Platform (GCP)
Earth Engine on Google Cloud Platform (GCP)Earth Engine on Google Cloud Platform (GCP)
Earth Engine on Google Cloud Platform (GCP)
 
Get your Git on GitHub
Get your Git on GitHubGet your Git on GitHub
Get your Git on GitHub
 
Run C++ as serverless with GCP Cloud Functions
Run C++ as serverless with GCP Cloud FunctionsRun C++ as serverless with GCP Cloud Functions
Run C++ as serverless with GCP Cloud Functions
 
Effective Tech Community Engagement - Best Practices
Effective Tech Community Engagement - Best PracticesEffective Tech Community Engagement - Best Practices
Effective Tech Community Engagement - Best Practices
 
Rajasthan IT Day Hackathon Finals
Rajasthan IT Day Hackathon FinalsRajasthan IT Day Hackathon Finals
Rajasthan IT Day Hackathon Finals
 
Arvind Brands - Hackathon - Solution Idea
Arvind Brands - Hackathon - Solution IdeaArvind Brands - Hackathon - Solution Idea
Arvind Brands - Hackathon - Solution Idea
 
Intro to Virtualization - 10000 feet view
Intro to Virtualization - 10000 feet viewIntro to Virtualization - 10000 feet view
Intro to Virtualization - 10000 feet view
 
Accenture Hack Forward - Finals
Accenture Hack Forward - FinalsAccenture Hack Forward - Finals
Accenture Hack Forward - Finals
 

Último

Último (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

Docker Introductory workshop

  • 2.
  • 3. What is Docker? Docker is an open-source project that automates the deployment of applications inside software containers.
  • 4. What is Docker? “an open platform for developers and sysadmins to build, ship, and run distributed applications”
  • 6. Why Docker? “Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries – anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.” source: https://www.docker.com/what-docker
  • 10. Docker accesses virtualisation features of Linux
  • 13.
  • 14. Can I install Docker from commandline? Yes! from get.docker.com
  • 15.
  • 16. Finding Docker version $ docker version
  • 17. Finding details of a Docker installation $ docker info
  • 18. How to do “hello world” in Docker? $ docker run docker/whalesay cowsay Hello World
  • 19. How to do “Hello World” in Docker? $ docker run docker/whalesay cowsay "Hello world" Runs a command in a new container Base image for creating the container Command name to run within the container Argument to the “cowsay” command
  • 20. How to do “hello world” in Docker? $ docker run -it hello-world
  • 21. How to get help on commands to use? $ docker --help
  • 22. Docker commands look like Linux commands - so familiarity with Linux commands can really help to get up to speed quickly with Docker.
  • 23. Docker Images “Images are blueprints for containers”
  • 24. How to get list of images? $ docker images
  • 25. How to search for an image? $ docker search <image_name>
  • 26. How to get an image? $ docker pull <image_name> In my case fedora image was already pulled. If it were not there, Docker would have pulled it afresh
  • 27. Choose smaller images ❖ Example: Alpine vs. Fedora (5 MB vs. 205 MB) alpine latest 4e38e38c8ce0 4 weeks ago 4.799 MB fedora latest f9873d530588 4 weeks ago 204.4 MB ❖ Prefer choosing a smaller base image that provides equivalent functionality (for your requirement) instead of choosing a larger one
  • 28. How to get details of an image? $ docker inspect <image_name>
  • 29. How to see “layers” in an image? $ docker history <image_name> Each of these lines are layers and the size column shows the exact size of each layer in the image
  • 30. How can I load and store images? $ docker save <image_name> -o <filename.tar> $ docker load –i <filename.tar>
  • 31. How do I delete an image? $ docker rmi <image-tag>
  • 32. How to delete all docker images? $ docker rmi $(docker images -q) docker images -q lists all image ids ❖ Avoid “Image Sprawl” ❖ Remove unused images and release disk space
  • 33. How to find “dangling images”? $ docker images -f "dangling=true" ❖ Remove “dangling images” using the command below: $ docker rmi $(docker images -f "dangling=true" -q)
  • 35. How to get list of containers? $ docker ps -a
  • 36. How to run a container? $ docker run OPTIONS <image-tag> CMD ARGS $ docker run fedora /bin/echo 'Hello world' Image name Command argument Command name
  • 37. How to run a container interactively? $ docker run –i -t fedora /bin/bash Interactive Run in terminal
  • 38. Cobb’s Totem - The Top
  • 40. How to run a container in the background? $ docker run -d alpine /bin/sh -c "while true; do echo current date and time is: $(date); sleep 10; done" Detach
  • 41. How to expose/map a port? $ docker inspect c7ada3308269 | grep Port $ docker run –d –p 80:80 nginx Mapped port - nginx host port (on which this command is run)
  • 42. Using Nginx Type http://localhost:80 in your browser window
  • 43. How to expose a port? $ docker run -d -p 80 --name mynginx nginx $ docker inspect mynginx | grep Port randomly assigned and mapped port number (by docker) host port; since no explicit mapped port is provided, a random port is assigned
  • 44. How to expose all exposed ports? $ docker run -d -P --name mynginx nginx $ docker port mynginx -P publishes all exposed ports to random ports
  • 45. Exposing ports $ docker run -d -p 80 --name nginx1 nginx d415758906dccc07aae319fc438c825e878ea00ffd58551c63d5c41fd39e4153 $ docker port nginx1 80/tcp -> 0.0.0.0:32769 Maps the port 80 from container to a random port in the host $ docker run -d -p 80:80 --name nginx2 nginx 4d7c26218b440d054d33799b7be1174254db50550254211d739f9403ca4092e9 $ docker port nginx2 80/tcp -> 0.0.0.0:80 Maps the port 80 from container to port 80 in the host $ docker run -d -p 80:80 -p 443:443 --name nginx3 nginx 2cfde425380601479aaf5e33a9b1fc09111d84b49595c33f509c00ad2cafc12d $ docker port nginx3 80/tcp -> 0.0.0.0:80 443/tcp -> 0.0.0.0:443 Maps the container ports 80 and 443 to the same port nos. in the host $ docker run -d -P --name nginx4 nginx 8e5fadfbcf5f3145909aed3219738535ad81e534153d5958fbec07f9e9c49e67 $ docker port nginx4 443/tcp -> 0.0.0.0:32770 80/tcp -> 0.0.0.0:32771 Maps the container ports 80 and 443 to random port nos. in the host The exposed ports in “nginx:latest” are “443/tcp" and “80/tcp”
  • 46. How to attach to a running container? $ docker attach <container_id> $ docker run –d ubuntu /bin/sh -c "while true; do echo current date and time is: $(date); sleep 10; done" short for “—detach” and it runs container in the background The “attach” command attaches to a running container
  • 47. How to detach from a running container (without exiting)? From docker documentation # To detach the tty without exiting the shell, # use the escape sequence Ctrl-p + Ctrl-q
  • 48. How to get list of containers? $ docker ps
  • 49. How do I see all the containers? $ docker ps -a
  • 50. Explicitly remove exited containers ❖ Explicitly use "rm" to remove the container from the file system - otherwise, even if the container exits, it is not cleaned up yet (and will hog memory).
  • 51. How do I remove a container? $ docker stop <container_id> You have to first stop a container before trying to remove it $ docker rm <container_id>
  • 52. How to remove all the containers? $ docker stop $(docker ps -a -q) $ docker rm $(docker ps -a –q) Note how the output shows no containers
  • 53. How to debug on a running container? $ docker exec –it <container_id> <cmd>
  • 54. Using nginx Nginx exposes ports 80; -P maps them randomly in the custom ports range $ docker run –d –name mynginx –P nginx
  • 55. Using nginx - Example $ cat Dockerfile FROM nginx:latest MAINTAINER Runcy Oommen ADD ./index.html /usr/share/nginx/html/index.html EXPOSE 80 $ cat index.html <h1> welcome to Dockerizing apps! <h1> $ docker build . Sending build context to Docker daemon 3.072 kB // output cropped ... Removing intermediate container b043a75a4e1c Successfully built 1aae04309f8b $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 1aae04309f8b 6 seconds ago 182.8 MB $ docker run -p 80:80 -d 1aae04309f8b 984c179231188445289e70d854250e4e981b77a899208360db4466e73930be42 $ curl localhost:80 <h1> welcome to Dockerizing apps! <h1> Type “localhost:80” in the browser address bar
  • 56. How do I run a C program? $ cat Dockerfile FROM gcc:latest MAINTAINER Runcy Oommen version: 0.1 COPY . /usr/src/mycapp WORKDIR /usr/src/mycapp RUN gcc -o first first.c CMD ["./first"] $ cat first.c #include <stdio.h> int main() { printf("hello worldn"); } $ docker build . –t "mycapp:latest" Sending build context to Docker daemon 3.072 kB Step 1 : FROM gcc:latest ---> a0b516dc1799 // .. steps cropped... Successfully built f99e7f18fa42 $ docker run -it mycapp hello world
  • 57. How do I run a Java program?$ cat Dockerfile FROM java:latest COPY . /usr/src/ WORKDIR /usr/src/ RUN javac hello.java CMD ["java", "hello"] $ cat hello.java class hello { public static void main(String []args) { System.out.println("hello world"); } } $ docker build . –t "myjavaapp:latest" Sending build context to Docker daemon 3.072 kB Step 1 : FROM java:latest ---> 264282a59a95 // intermediate steps cropped Successfully built 0d7a3a12ba9d $ docker run myjavaapp hello world
  • 58. Beware of “container sprawl” ❖ Application broken to run in “too many containers“ can be difficult to deal with! “Breaking deployments into more functional discrete parts is smart, but that means we have MORE PARTS to manage. There's an inflection point between separation of concerns and sprawl.” -- Rob Hirschfeld (OpenStack Foundation board member)
  • 60. Different ways to create images docker commit Build an image from a container docker build Create an image from a Dockerfile by executing the build steps given in the file docker import Create a base image by importing from a tarball. [import is mainly used for creating base-images; first two options are widely used]
  • 61. Dockerfile - key instructions FROM The base image for building the new docker image; provide “FROM scratch” if it is a base image itself MAINTAINER The author of the Dockerfile and the email RUN Any OS command to build the image CMD Specify the command to be started when the container is run; can be overridden by the explicit argument when providing docker run command ADD Copies files or directories from the host to the container in the given path EXPOSE Exposes the specified port to the host machine
  • 63. Docker volume commands Command Description docker volume create Create a volume docker volume inspect Display detailed information on one or more volumes docker volume ls List the available volumes docker volume rm Remove one or more volumes
  • 64. Commands for Docker volumes $ docker volume create --name myvolume myvolume $ docker volume ls local myvolume $ docker volume inspect myvolume [ { "Name": "myvolume", "Driver": "local", "Mountpoint": "/var/lib/docker/volumes/myvolume/_data", "Labels": {}, "Scope": "local" } ] $ docker volume rm myvolume myvolume
  • 65. How to persist data? $ docker run -v /volumetesting --name="persistdata" alpine /bin/sh -c "echo testing persistence with volumes > /volumetesting/textfile.txt” $ docker run --volumes-from=persistdata alpine /bin/sh -c "cat /volumetesting/textfile.txt" testing persistence with volumes Use -v option to “mount volumes”
  • 66. Removing volumes $ docker volume rm <volume_name>
  • 67. Removing containers with volumes ❖ When the container is removed, the volumes will not be removed. If the volumes also need to be removed, you have to use the -v option $ docker rm –v <sha256_hash>
  • 68. Clean up volumes ❖ You can “clean up” the volumes if you aren't using them. $ docker volume rm $(docker volume ls -q)
  • 70. docker-compose commands Command Description docker-compose up (Re)build services docker-compose kill Kill the containers docker-compose logs Show the logs of the containers docker-compose down Stop and remove images, containers, volumes and networks docker-compose rm Remove stopped containers
  • 71. Creating multiple Docker containers Step 1. Create a docker-compose.yml file Step 2. Execute “docker-compose up -d” Step 3. Execute “docker-compose logs” from another shell (but from same dir) Step 4. Execute “docker-compose down”
  • 73. Getting the ip address of a container $ docker inspect --format '{{ .NetworkSettings.IPAddress }}' fervent_sinoussi 172.17.0.6 $ docker attach fervent_sinoussi root@856aed6a92f1:/# ip addr // ... 92: eth0@if93: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:ac:11:00:06 brd ff:ff:ff:ff:ff:ff inet 172.17.0.6/16 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::42:acff:fe11:6/64 scope link valid_lft forever preferred_lft forever root@856aed6a92f1:/# cat /etc/hosts // ... 172.17.0.6 856aed6a92f1 root@856aed6a92f1:/# There are many ways to get the IP address of a container: 1. Use the docker inspect command 2. Use ip addr command from the container’s shell 3. Use “cat /etc/hosts” and check the entry for the container
  • 74. How to get port mappings of a container? $ docker port <container_id>
  • 75. Three kinds of networks $ docker network ls By default, containers are added to the bridge network. You can see the containers in bridge network here
  • 76. Docker network commands Command Description docker network connect Connect a container to a network docker network create Create a network docker network disconnect Disconnect a container from a network docker network inspect Display detailed information on one or more networks docker network ls List networks docker network rm Remove one or more networks
  • 78. Docker security “One primary risk with running Docker containers is that the default set of capabilities and mounts given to a container may provide incomplete isolation, either independently, or when used in combination with kernel vulnerabilities” Source: https://docs.docker.com/engine/security/security/
  • 79. Docker workbench for security git clone https://github.com/docker/docker-bench-security.git cd docker-bench-security sh docker-bench-security.sh git clone https://github.com/docker/docker-bench-security.git cd docker-bench-security docker-compose run --rm docker-bench-security OR ❖ Use the free Docker Workbench For Security to check for violations of security best practices
  • 82. Stats for all running containers $ docker stats Displays resource utilisation (cpu, memory, etc) details; automatically updated when details change
  • 83. Stats for a specific Docker $ docker stats <CONTAINTER_ID>
  • 85. ‘RunC’ container runtime RunC is the name of the container runtime used by Docker It is part of OCI (Open Container Initiative) https://runc.io/
  • 86. Can I use GUI instead of command- line? Use “kitematic” (https://github.com/docker/kitematic)
  • 87. Crazy stuff: Docker in Docker!! $ docker run --privileged -d docker:dind" “docker:dind” is the official “Docker In Docker image” See: https://github.com/jpetazzo/dind
  • 91. Docker is *completely* portable There are limitations to portability with Docker (depending on what you mean by “portable”). For example, you can run a Windows Docker container only on Windows and run a Linux Docker container only on Linux (and not vice versa). Build once, run anywhere - but conditions apply!
  • 92. “Management says we need Docker, so let’s use it”
  • 97. Where to learn more?
  • 98. Relevant URLs ❖ Docker resources list: https://github.com/hangyan/docker-resources ❖ Self-learning courses: https://training.docker.com/ ❖ Detailed documentation: https://docs.docker.com/ ❖ Various presentations: http://container.training ❖ SE-Radio Episode 217: James Turnbull on Docker
  • 99. DOCKER: UP & RUNNING➤ Covers how to develop, test, debug, ship, scale, and support with Docker from DevOps perspective ➤ We liked the useful tips; examples: ➤ “Maximize robustness with fast startup and graceful shutdown.” ➤ “Explicitly declare and isolate dependencies.” ➤ “Strictly separate build and run stages.” http://amzn.com/1491917571 “Docker: Up & Running”, Karl Matthias, Sean P. Kane, O'Reilly Media; 1 edition (July 3, 2015)
  • 100. THE DOCKER BOOK➤ Interesting sub-title: “Containerization is the new virtualization”. ➤ From James Turnbull (CTO at Kickstarter and Advisor at Docker) ➤ Useful to get comfortable with core concepts of Docker ➤ Useful for developers, operations staff (and DevOps), and SysAdmins ➤ Supporting website: http://dockerbook.com/ http://www.amazon.in/dp/B00LRROTI4 The Docker Book, James Turnbull, Amazon Digital South Asia Services, July 2014
  • 101. DOCKER COOKBOOK➤ Contents written in recipe format (Problem, Solution, Discussion) ➤ Useful because we can look for solutions to the problems that we face when using Docker ➤ What we like: it covers topics that are not covered well in other books including Kubernetes, Docker ecosystem tools, monitoring Docker, and application use cases (CI, CD) http://amzn.com/149191971X “Docker Cookbook”, Sébastien Goasguen, O'Reilly Media, 2015
  • 102. ❖ Book organized into three parts: ❖ Background and Basics ❖ The Software Lifecycle with Docker ❖ Tools and Techniques ❖ Useful example: Walks you through the steps to develop and deploy web applications with Docker ❖ Though the book touches upon basics, it covers more advanced topicshttp://amzn.com/1491915765 Using Docker: Developing and Deploying Software with Containers, Adrian Mouat, O'Reilly Media, 2016 USING DOCKER