SlideShare a Scribd company logo
Getting started with
Docker
Geeta Vinnakota
Next 45 minutes
 What is docker and how can it help us?
 What is containerization and why does that matter?
 How is containerization different from virtualization?
How to install docker on Linux?
What is an image?
How do you build an image?
 What is a Dockerfile and why is it necessary?
How is a container different from an image?
 How does a docker deployment work flow with look like?
Command Reference
2/4/2016 1
Why Docker?
• Eliminate “But it works on my computer!” nightmares during deployments, by
exactly mirroring development and production environments
• Support quick replication of new production servers ~ within minutes
• Allows quick rollbacks ~ within minutes
• Advanced multi-container dockers play well with micro-service architecture by
enabling de-coupling and portability
( Keep an eye out and ask yourself, how these benefits are realized in the workflow, as you proceed with
the deck )
2/4/2016 2
What is Docker?
• What is Docker?
• Docker manages containers
• Docker allows shipping applications, code and services in containers
• What is a container?
• Containers can be compared to virtual machines, but much light-weight, faster with
less overhead
• Containers are isolated, independent, portable and easily reproducible
• Containerization vs Virtualization
• For an abstract view, containerization can be compared with virtualization
2/4/2016 3
Virtualization
2/4/2016 4
Image by Laura Frank, Sr Developer at Codeship
• Here is a host computer
with an installed hypervisor
• Hypervisor supports virtual
machines on a host
computer
• There are 3 virtual
machines installed on a
host in this diagram
• They share the resources of
the host computer
Containerization
2/4/2016 5
Image by Laura Frank, Sr Developer at Codeship
• Here is another host
computer
• Notice, that there is no
hypervisor or guest OS
Containerization
2/4/2016 6
Image by Laura Frank, Sr Developer at Codeship
• Instead of a hypervisor,
there is a container engine
• 3 containers are running
on the container engine
Docker ecosystem
provides us with a
container engine along
with a set of tools that
help us build and manage
containers
Installation
2/4/2016 7
Installating docker on Linux (ubuntu)
sudo apt-get update get latest package version
curl –sSL https://get.docker.com/ | sh install docker
docker -v check version
sudo usermod –aG docker ubuntu add default user ubuntu to docker group
docker info
docker history
• Linux – Package Installation described above
• Mac/Windows – Docker Toolbox. ( boot2docker is old and deprecated )
Images
2/4/2016 9
What is an image?
• An image is a template for a container
• It could be a simple command or complex software
• An image layer is a file system that is read-only
• A R-W file system is installed on top of the image layers
2/4/2016 10
How image builds work?
• After each RUN docker looks for a matching image in the build cache
• Build command compresses the context into an archive/tar and sends
it to the daemon
2/4/2016 11
How is an image different from a container?
Image
• Image is similar to a class in
programming
• Image ~ Blueprint
• Image is what you store on docker hub
& pass around
Container
• Container is similar an instance of the class
• Container ~ Actual Object
• You do not store containers anywhere or
pass them around
2/4/2016 12
• Consider the following differences and analogies to avoid confusion between images and
containers.
Types of Images
Service Image Project Base Image Official Image
• Offers a service out of the box
• You have to do very little to get
it functioning
• Nginx, Postgres, MySQL
• No service is offered out of the
box
• Ruby, Language based images
• Add your own code on top of
the image
• Maintained by the organization
or company itself
• An official image can serve as a
service or project based image
2/4/2016 13
Image Command Reference
Build an Image docker build –t repo_name/img_name:tag . build images from Dockerfile and
context
-t Tag the image with a repo name
Repo Name –
username/imagename
Rename docker tag local_repo:tag
docker_hub_repo:tag
Rename an image
docker tag img_id docker_hub_repo:tag Rename an image
List docker images List images
Remove docker rmi –f img_id/img_name Remove image
Inspect Details docker inspect img_id/img_name List port bindings, config
Login to Docker Hub docker login –username=uname –
password=pw –email=email
Pull Image from Hub docker pull username/image_name:tag
What is Dockerfile?
• A Dockerfile lets you create your own image
• It is a series of instructions to build your own image
• INSTRUCTIONS are typically upper case
• Best Practices
• Split long commands with backslashes
• Prefer COPY to ADD
• Minimize image layers by combining multiple RUN commands to avoid
multiple intermediate images, keeping readability in mind.
2/4/2016 15
Dockerfile Instruction Reference
Instruction Example Details
FROM FROM nginx Mandatory. First instruction.
Specifies base image
RUN RUN rm
/etc/nginx/defa
ult.conf
Execute the command while on the container
WORKDIR WORKDIR
/users/dan
Specify the working directory for the RUN commands
By default they are run in the root directory
CMD ping localhost Specify the default command of the image, that is run, when the
container is launched.
If there are multiple, the last one takes precedence
Process that runs with the container
Dockerfile Instruction Reference
EXPOSE EXPOSE 80 Expose ports on the container.
Does not map them to hosts
VOLUME VOLUME /var/log/nginx Creates a mount point with the specified name.
Marks it as holding volumes from native host
Does not map any volumes from the host
COPY COPY build/artifacts
/usr/share/nginx/html
Copies files from host to container
ADD Similar to COPY, but has additional capabilities of uncompressing
tar files, fetching files from remote locations
Prefer COPY to ADD unless specifically required
ENTRYPOINT Similar to CMD
Containers
2/4/2016 18
What is a container?
• Typically containers run a single process(default command).
Containers can be thought of, as the process they run.
• Container runs only as long as the default command is running
• Container itself is a process in the host machine. Any process run by
the container is a child process
• Containers have internal IP address
2/4/2016 19
How is a container different from a Virtual
Machine
• Container looks and operates like a Virtual Machine, but it is not a VM
• Containers are light weight. Spin up faster
• A host can accommodate more containers than VMs
• Containers run on top of docker engine
2/4/2016 20
Container Best Practices & Usecases
• Best Practices
• Specify names for containers to avoid strange auto generated names
• Containers are not suitable for persistent data, as they are ephemeral and
should allow stopping, destroying and recreating
• Do not run ssh servers in containers unless needed
• Use docker commands to check logs, restart processes, tweak configuration,
run upgrades
• Usecases
• Deploy web front-end applications
• Deploy web APIs
• Run Maintenance scripts
2/4/2016 21
Container Command Reference
Purpose Example Details
Run a container docker run –name docker-nginx –p
80:80 –d nginx
Creates a container with name
docker-nginx from image nginx
Flags for run -d Detached mode. Container runs in
the background and keeps running
until manually stopped
-p 80:80 Map local machine port 80 to
container port 80
Inspect docker inspect container_id | grep
IpAddress
List docker ps -a List containers including those that
are stopped
Troubleshooting a Container
Stop a container docker stop c_id Stop container with id c_id
Remove docker rm c_name Remove container with name
c_name
Enter a container docker exec –it c_id bash Takes you inside of a running
container to the bash
-it interactive ( also works with run
)
View logs from container docker logs c_id print logs of pid 1 process from the
container
docker logs –f c_id Follow logs from the container
docker logs –f –tail 10 c_id Follow logs from the last 10 lines
What is Docker Hub?
• Place to store and distribute docker images
• Think of it as github but for docker images
• Docker logo or prefix of library ‘library/nginx’ denotes official images
in the hub
• 70+ official, 100K+ regular, 300M+ downloads
2/4/2016 24
Traditional Deployment Workflow
2/4/2016 25
2/4/2016 26
• In a traditional
deployment flow, you
start with the host
machine
Traditional Deployment Workflow – Step 1 of 5
2/4/2016 27
• Install the
necessary tools
and services
• Start with
Installing Nginx
Nginx
Traditional Deployment Workflow – Step 2 of 5
2/4/2016 28
• Then more
software
provisioning
and
installations
• Ruby platform
Nginx
Ruby
Traditional Deployment Workflow – Step 3 of 5
2/4/2016 29
• Install the
necessary
dependencies
Nginx
Ruby
Dependencies
Traditional Deployment Workflow – Step 4 of 5
2/4/2016 30
• Finally deploy
the application
code and tie
everything
together into
an ecosystem
Nginx
Ruby
Dependencies
Application
Traditional Deployment Workflow – Step 5 of 5
Deployment Workflow with
Docker
2/4/2016 31
2/4/2016 32
• In Docker deployment
flow, we start with
installing docker enginer
on the host computer
• Cloud providers like
AWS provide machines
pre-provisioned with
docker, ready to use
Docker
Engine
Deployment Workflow with Docker – Step 1 of 2
2/4/2016 33
• Ship the entire
ecosystem, as a
container from your
development
environment ( as
opposed to
provisioning each
software separately )
Nginx
Ruby
Dependencies
Application
Docker
Engine
Deployment Workflow with Docker – Step 2 of 2
Production
Server
Docker
Image
Prd
Deploy
Package
Staging
Server
QA
Deploy
Package
Development
Machine
Image =
Application Code +
Software Needed to Run
the code
Deploy Package =
Location of Image on Hub
+ Access Credentials
• Image is nothing but a
versioned artifact
• Notice how all 3 versions
run the same image
• Which is what leads to no
surprise deploys ( exact
mirroring of development,
staging and production
servers
2/4/2016 35
Code Change
Create new docker image
docker build –t
repo/username:tag .
Push image to docker hub
docker push
repo/username:tag
Update image tag version
in dockerrun.aws.json
Web
or
CLI
Create a zip file (use gulp) with
dockerrun.aws.json &
.ebextensions. Upload it via
webconsole
CLI
’eb deploy’ Uploads a zip of
dockerrun.aws.json &
.ebextensions
Web CLI
Deploy Workflow
Docker using EB (Elastic
Beanstalk)
Tells Elastic Beanstalk
the location of the
docker image
Eliminate unrequired
files in image build by
adding .dockerignore
Tell EB to to pick only
dockerrun.aws.json
while create zip via
.ebignore
Advanced Features
2/4/2016 36
Volumes
• Volumes are mounted when creating a container
• Data in this volume is persistent even if the container is deleted
• Volumes are independent of the container lifecycle
• Volumes can be shared between containers
• Specify volumes in dockerfile using VOLUME instruction
• Best Practices:
• Mounting volumes from host for persistent data is not recommended as it
binds you to that host
• Cannot map volumes from host using dockerfile as it is intended to work on
any host
2/4/2016 37
Container Linking
• Container connection without using any network ports
• Step-1: Create the source container
• Step-2: Create the recipient container, with link to the source. It
creates an entry in the recipient with an alias and IP of the source
• Usecase: when you have separate web and database containers
• Source and recipient Containers can be on the same or different hosts
2/4/2016 38

More Related Content

What's hot (20)

PDF
Under the Hood with Docker Swarm Mode - Drew Erny and Nishant Totla, Docker
Docker, Inc.
 
PDF
Ansible not only for Dummies
Łukasz Proszek
 
PPTX
Docker toolbox
Yonghwee Kim
 
PDF
Docker
Chen Chun
 
PPTX
Docker Introductory workshop
Runcy Oommen
 
PPTX
Installaling Puppet Master and Agent
Ranjit Avasarala
 
PPTX
Installation Openstack Swift
ymtech
 
PPTX
Docker 1.11 Presentation
Sreenivas Makam
 
PDF
What's New in Docker 1.12?
Ajeet Singh Raina
 
PPTX
CoreOS Overview and Current Status
Sreenivas Makam
 
PDF
Plug-ins: Building, Shipping, Storing, and Running - Nandhini Santhanam and T...
Docker, Inc.
 
PDF
Docker at Djangocon 2013 | Talk by Ken Cochrane
dotCloud
 
PPTX
Docker Swarm for Beginner
Shahzad Masud
 
PDF
Continuous Integration: SaaS vs Jenkins in Cloud
Ideato
 
PDF
Amazon EC2 Container Service in Action
Remotty
 
PDF
Docker Swarm 0.2.0
Docker, Inc.
 
PDF
Deep Dive into Docker Swarm Mode
Ajeet Singh Raina
 
PDF
Docker.io
Ladislav Prskavec
 
PPTX
Deploying Symfony2 app with Ansible
Roman Rodomansky
 
PDF
Running Django on Docker: a workflow and code
Danielle Madeley
 
Under the Hood with Docker Swarm Mode - Drew Erny and Nishant Totla, Docker
Docker, Inc.
 
Ansible not only for Dummies
Łukasz Proszek
 
Docker toolbox
Yonghwee Kim
 
Docker
Chen Chun
 
Docker Introductory workshop
Runcy Oommen
 
Installaling Puppet Master and Agent
Ranjit Avasarala
 
Installation Openstack Swift
ymtech
 
Docker 1.11 Presentation
Sreenivas Makam
 
What's New in Docker 1.12?
Ajeet Singh Raina
 
CoreOS Overview and Current Status
Sreenivas Makam
 
Plug-ins: Building, Shipping, Storing, and Running - Nandhini Santhanam and T...
Docker, Inc.
 
Docker at Djangocon 2013 | Talk by Ken Cochrane
dotCloud
 
Docker Swarm for Beginner
Shahzad Masud
 
Continuous Integration: SaaS vs Jenkins in Cloud
Ideato
 
Amazon EC2 Container Service in Action
Remotty
 
Docker Swarm 0.2.0
Docker, Inc.
 
Deep Dive into Docker Swarm Mode
Ajeet Singh Raina
 
Deploying Symfony2 app with Ansible
Roman Rodomansky
 
Running Django on Docker: a workflow and code
Danielle Madeley
 

Viewers also liked (20)

PDF
Docker 101: Introduction to Docker
Docker, Inc.
 
PDF
Fake it till You Make it (Pick up New IT Skills Like a Maniac)
Hank Huang
 
PPT
Srv p18-intro-v30
Bertalan EGED
 
PPS
A lógica da reencarnação
Marcos Arouca
 
PPTX
VM Farms Thrive with Dedicated IP Storage Networks
Brocade
 
PDF
Liliana rivas gonzalez_actividad1_mapa_c
lilianarigo
 
PDF
Docker 101 2015-05-28
Adrian Otto
 
PPT
Nginx internals
liqiang xu
 
PPT
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...
addame
 
PPTX
Nginx
Geeta Vinnakota
 
PDF
Introducing Docker
Francesco Pantano
 
PDF
Lcu14 Lightning Talk- NGINX
Linaro
 
PDF
Docker use dockerfile
cawamata
 
PPTX
Introduction to Docker - What is it and how is it compared to VM's
Jeremy Haas
 
PPTX
Docker Internals - Twilio talk November 14th, 2013
Guillaume Charmes
 
PPTX
Learn nginx in 90mins
Larry Cai
 
PPTX
Docker
Cary Gordon
 
PDF
Docker for Developers
Chris Tankersley
 
PDF
How to secure your web applications with NGINX
Wallarm
 
PDF
Docker volume
MyoungSu Shin
 
Docker 101: Introduction to Docker
Docker, Inc.
 
Fake it till You Make it (Pick up New IT Skills Like a Maniac)
Hank Huang
 
Srv p18-intro-v30
Bertalan EGED
 
A lógica da reencarnação
Marcos Arouca
 
VM Farms Thrive with Dedicated IP Storage Networks
Brocade
 
Liliana rivas gonzalez_actividad1_mapa_c
lilianarigo
 
Docker 101 2015-05-28
Adrian Otto
 
Nginx internals
liqiang xu
 
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...
addame
 
Introducing Docker
Francesco Pantano
 
Lcu14 Lightning Talk- NGINX
Linaro
 
Docker use dockerfile
cawamata
 
Introduction to Docker - What is it and how is it compared to VM's
Jeremy Haas
 
Docker Internals - Twilio talk November 14th, 2013
Guillaume Charmes
 
Learn nginx in 90mins
Larry Cai
 
Docker
Cary Gordon
 
Docker for Developers
Chris Tankersley
 
How to secure your web applications with NGINX
Wallarm
 
Docker volume
MyoungSu Shin
 
Ad

Similar to Getting Started with Docker (20)

PPTX
Containerization using docker and its applications
Puneet Kumar Bhatia (MBA, ITIL V3 Certified)
 
PPTX
Containerization using docker and its applications
Puneet Kumar Bhatia (MBA, ITIL V3 Certified)
 
PDF
[@NaukriEngineering] Docker 101
Naukri.com
 
PPTX
Powercoders · Docker · Fall 2021.pptx
IgnacioTamayo2
 
PPTX
Java Developer Intro to Environment Management with Vagrant, Puppet, and Dock...
Lucas Jellema
 
PDF
Introduction to Docker - Learning containerization XP conference 2016
XP Conference India
 
PPTX
Java developer intro to environment management with vagrant puppet and docker
Getting value from IoT, Integration and Data Analytics
 
PDF
Docker From Scratch
Giacomo Vacca
 
PDF
Docker
Brian Hogan
 
PDF
Up and running with docker
Michelle Liu
 
PDF
Cloud Native Computing - Part III - Containers
Linjith Kunnon
 
PDF
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Codemotion
 
PPTX
Academy PRO: Docker. Part 2
Binary Studio
 
PDF
Docker puebla bday #4 celebration
Ramon Morales
 
PPTX
Dockerizing a Symfony2 application
Roman Rodomansky
 
PPTX
Docker presentation
Shankar Chaudhary
 
PDF
Docker Up and Running for Web Developers
Amr Fawzy
 
PDF
Docker up and Running For Web Developers
BADR
 
PPTX
Dockers and containers basics
Sourabh Saxena
 
PDF
Docker Essentials Workshop— Innovation Labs July 2020
CloudHero
 
Containerization using docker and its applications
Puneet Kumar Bhatia (MBA, ITIL V3 Certified)
 
Containerization using docker and its applications
Puneet Kumar Bhatia (MBA, ITIL V3 Certified)
 
[@NaukriEngineering] Docker 101
Naukri.com
 
Powercoders · Docker · Fall 2021.pptx
IgnacioTamayo2
 
Java Developer Intro to Environment Management with Vagrant, Puppet, and Dock...
Lucas Jellema
 
Introduction to Docker - Learning containerization XP conference 2016
XP Conference India
 
Java developer intro to environment management with vagrant puppet and docker
Getting value from IoT, Integration and Data Analytics
 
Docker From Scratch
Giacomo Vacca
 
Docker
Brian Hogan
 
Up and running with docker
Michelle Liu
 
Cloud Native Computing - Part III - Containers
Linjith Kunnon
 
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Codemotion
 
Academy PRO: Docker. Part 2
Binary Studio
 
Docker puebla bday #4 celebration
Ramon Morales
 
Dockerizing a Symfony2 application
Roman Rodomansky
 
Docker presentation
Shankar Chaudhary
 
Docker Up and Running for Web Developers
Amr Fawzy
 
Docker up and Running For Web Developers
BADR
 
Dockers and containers basics
Sourabh Saxena
 
Docker Essentials Workshop— Innovation Labs July 2020
CloudHero
 
Ad

Recently uploaded (20)

PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 

Getting Started with Docker

  • 2. Next 45 minutes  What is docker and how can it help us?  What is containerization and why does that matter?  How is containerization different from virtualization? How to install docker on Linux? What is an image? How do you build an image?  What is a Dockerfile and why is it necessary? How is a container different from an image?  How does a docker deployment work flow with look like? Command Reference 2/4/2016 1
  • 3. Why Docker? • Eliminate “But it works on my computer!” nightmares during deployments, by exactly mirroring development and production environments • Support quick replication of new production servers ~ within minutes • Allows quick rollbacks ~ within minutes • Advanced multi-container dockers play well with micro-service architecture by enabling de-coupling and portability ( Keep an eye out and ask yourself, how these benefits are realized in the workflow, as you proceed with the deck ) 2/4/2016 2
  • 4. What is Docker? • What is Docker? • Docker manages containers • Docker allows shipping applications, code and services in containers • What is a container? • Containers can be compared to virtual machines, but much light-weight, faster with less overhead • Containers are isolated, independent, portable and easily reproducible • Containerization vs Virtualization • For an abstract view, containerization can be compared with virtualization 2/4/2016 3
  • 5. Virtualization 2/4/2016 4 Image by Laura Frank, Sr Developer at Codeship • Here is a host computer with an installed hypervisor • Hypervisor supports virtual machines on a host computer • There are 3 virtual machines installed on a host in this diagram • They share the resources of the host computer
  • 6. Containerization 2/4/2016 5 Image by Laura Frank, Sr Developer at Codeship • Here is another host computer • Notice, that there is no hypervisor or guest OS
  • 7. Containerization 2/4/2016 6 Image by Laura Frank, Sr Developer at Codeship • Instead of a hypervisor, there is a container engine • 3 containers are running on the container engine Docker ecosystem provides us with a container engine along with a set of tools that help us build and manage containers
  • 9. Installating docker on Linux (ubuntu) sudo apt-get update get latest package version curl –sSL https://get.docker.com/ | sh install docker docker -v check version sudo usermod –aG docker ubuntu add default user ubuntu to docker group docker info docker history • Linux – Package Installation described above • Mac/Windows – Docker Toolbox. ( boot2docker is old and deprecated )
  • 11. What is an image? • An image is a template for a container • It could be a simple command or complex software • An image layer is a file system that is read-only • A R-W file system is installed on top of the image layers 2/4/2016 10
  • 12. How image builds work? • After each RUN docker looks for a matching image in the build cache • Build command compresses the context into an archive/tar and sends it to the daemon 2/4/2016 11
  • 13. How is an image different from a container? Image • Image is similar to a class in programming • Image ~ Blueprint • Image is what you store on docker hub & pass around Container • Container is similar an instance of the class • Container ~ Actual Object • You do not store containers anywhere or pass them around 2/4/2016 12 • Consider the following differences and analogies to avoid confusion between images and containers.
  • 14. Types of Images Service Image Project Base Image Official Image • Offers a service out of the box • You have to do very little to get it functioning • Nginx, Postgres, MySQL • No service is offered out of the box • Ruby, Language based images • Add your own code on top of the image • Maintained by the organization or company itself • An official image can serve as a service or project based image 2/4/2016 13
  • 15. Image Command Reference Build an Image docker build –t repo_name/img_name:tag . build images from Dockerfile and context -t Tag the image with a repo name Repo Name – username/imagename Rename docker tag local_repo:tag docker_hub_repo:tag Rename an image docker tag img_id docker_hub_repo:tag Rename an image List docker images List images Remove docker rmi –f img_id/img_name Remove image Inspect Details docker inspect img_id/img_name List port bindings, config Login to Docker Hub docker login –username=uname – password=pw –email=email Pull Image from Hub docker pull username/image_name:tag
  • 16. What is Dockerfile? • A Dockerfile lets you create your own image • It is a series of instructions to build your own image • INSTRUCTIONS are typically upper case • Best Practices • Split long commands with backslashes • Prefer COPY to ADD • Minimize image layers by combining multiple RUN commands to avoid multiple intermediate images, keeping readability in mind. 2/4/2016 15
  • 17. Dockerfile Instruction Reference Instruction Example Details FROM FROM nginx Mandatory. First instruction. Specifies base image RUN RUN rm /etc/nginx/defa ult.conf Execute the command while on the container WORKDIR WORKDIR /users/dan Specify the working directory for the RUN commands By default they are run in the root directory CMD ping localhost Specify the default command of the image, that is run, when the container is launched. If there are multiple, the last one takes precedence Process that runs with the container
  • 18. Dockerfile Instruction Reference EXPOSE EXPOSE 80 Expose ports on the container. Does not map them to hosts VOLUME VOLUME /var/log/nginx Creates a mount point with the specified name. Marks it as holding volumes from native host Does not map any volumes from the host COPY COPY build/artifacts /usr/share/nginx/html Copies files from host to container ADD Similar to COPY, but has additional capabilities of uncompressing tar files, fetching files from remote locations Prefer COPY to ADD unless specifically required ENTRYPOINT Similar to CMD
  • 20. What is a container? • Typically containers run a single process(default command). Containers can be thought of, as the process they run. • Container runs only as long as the default command is running • Container itself is a process in the host machine. Any process run by the container is a child process • Containers have internal IP address 2/4/2016 19
  • 21. How is a container different from a Virtual Machine • Container looks and operates like a Virtual Machine, but it is not a VM • Containers are light weight. Spin up faster • A host can accommodate more containers than VMs • Containers run on top of docker engine 2/4/2016 20
  • 22. Container Best Practices & Usecases • Best Practices • Specify names for containers to avoid strange auto generated names • Containers are not suitable for persistent data, as they are ephemeral and should allow stopping, destroying and recreating • Do not run ssh servers in containers unless needed • Use docker commands to check logs, restart processes, tweak configuration, run upgrades • Usecases • Deploy web front-end applications • Deploy web APIs • Run Maintenance scripts 2/4/2016 21
  • 23. Container Command Reference Purpose Example Details Run a container docker run –name docker-nginx –p 80:80 –d nginx Creates a container with name docker-nginx from image nginx Flags for run -d Detached mode. Container runs in the background and keeps running until manually stopped -p 80:80 Map local machine port 80 to container port 80 Inspect docker inspect container_id | grep IpAddress List docker ps -a List containers including those that are stopped
  • 24. Troubleshooting a Container Stop a container docker stop c_id Stop container with id c_id Remove docker rm c_name Remove container with name c_name Enter a container docker exec –it c_id bash Takes you inside of a running container to the bash -it interactive ( also works with run ) View logs from container docker logs c_id print logs of pid 1 process from the container docker logs –f c_id Follow logs from the container docker logs –f –tail 10 c_id Follow logs from the last 10 lines
  • 25. What is Docker Hub? • Place to store and distribute docker images • Think of it as github but for docker images • Docker logo or prefix of library ‘library/nginx’ denotes official images in the hub • 70+ official, 100K+ regular, 300M+ downloads 2/4/2016 24
  • 27. 2/4/2016 26 • In a traditional deployment flow, you start with the host machine Traditional Deployment Workflow – Step 1 of 5
  • 28. 2/4/2016 27 • Install the necessary tools and services • Start with Installing Nginx Nginx Traditional Deployment Workflow – Step 2 of 5
  • 29. 2/4/2016 28 • Then more software provisioning and installations • Ruby platform Nginx Ruby Traditional Deployment Workflow – Step 3 of 5
  • 30. 2/4/2016 29 • Install the necessary dependencies Nginx Ruby Dependencies Traditional Deployment Workflow – Step 4 of 5
  • 31. 2/4/2016 30 • Finally deploy the application code and tie everything together into an ecosystem Nginx Ruby Dependencies Application Traditional Deployment Workflow – Step 5 of 5
  • 33. 2/4/2016 32 • In Docker deployment flow, we start with installing docker enginer on the host computer • Cloud providers like AWS provide machines pre-provisioned with docker, ready to use Docker Engine Deployment Workflow with Docker – Step 1 of 2
  • 34. 2/4/2016 33 • Ship the entire ecosystem, as a container from your development environment ( as opposed to provisioning each software separately ) Nginx Ruby Dependencies Application Docker Engine Deployment Workflow with Docker – Step 2 of 2
  • 35. Production Server Docker Image Prd Deploy Package Staging Server QA Deploy Package Development Machine Image = Application Code + Software Needed to Run the code Deploy Package = Location of Image on Hub + Access Credentials • Image is nothing but a versioned artifact • Notice how all 3 versions run the same image • Which is what leads to no surprise deploys ( exact mirroring of development, staging and production servers
  • 36. 2/4/2016 35 Code Change Create new docker image docker build –t repo/username:tag . Push image to docker hub docker push repo/username:tag Update image tag version in dockerrun.aws.json Web or CLI Create a zip file (use gulp) with dockerrun.aws.json & .ebextensions. Upload it via webconsole CLI ’eb deploy’ Uploads a zip of dockerrun.aws.json & .ebextensions Web CLI Deploy Workflow Docker using EB (Elastic Beanstalk) Tells Elastic Beanstalk the location of the docker image Eliminate unrequired files in image build by adding .dockerignore Tell EB to to pick only dockerrun.aws.json while create zip via .ebignore
  • 38. Volumes • Volumes are mounted when creating a container • Data in this volume is persistent even if the container is deleted • Volumes are independent of the container lifecycle • Volumes can be shared between containers • Specify volumes in dockerfile using VOLUME instruction • Best Practices: • Mounting volumes from host for persistent data is not recommended as it binds you to that host • Cannot map volumes from host using dockerfile as it is intended to work on any host 2/4/2016 37
  • 39. Container Linking • Container connection without using any network ports • Step-1: Create the source container • Step-2: Create the recipient container, with link to the source. It creates an entry in the recipient with an alias and IP of the source • Usecase: when you have separate web and database containers • Source and recipient Containers can be on the same or different hosts 2/4/2016 38