SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
Introduction to Docker
SG PHP Meetup March 2015
About me
• Kuan-Yen Heng (Chris)
• Software Engineer at Pie
• kuanyen@pie.co
• https://github.com/gigablah
• @gigablah
lxc / libcontainer
cgroups
aufs
selinux
btrfs
devicemapper
chroot
namespaces
images
containers
volumes
libvirt
What’s Docker?
What’s Docker?
• Abstraction layer for Linux containers
• Written in Google Go (golang)
• Started as an internal project in dotCloud, a
PaaS company
• Open sourced in Mar 2013
• dotCloud pivots and becomes Docker, Inc
• Docker Machine, Swarm and Compose
announced in Dec 2014
Why Docker?
• Lightweight resource usage
• Extremely fast startup compared to VMs
• Repeatable, consistent builds (if careful)
• Dependency isolation
• Pristine host OS; only Docker needs to be
installed (easier updates)
Why Docker?
• If you want to…
• Upgrade PHP for an app but you have an old
vBulletin installation that needs PHP 5.3
• Run Python 2.7 and Python 3 apps
• Switch your OS entirely
• Get the same image to run on your laptop, your CI
service, staging and production without having to
“bake” different image formats
• Docker makes it relatively painless
Vagrant vs. Docker
• Vagrant is an abstraction layer for VMs
• Each VM is a system in its own right (allocated
resources, virtualised hardware)
• Docker containers, however, all make use of
the same underlying host kernel
• Processes in Docker run as regular processes
on the host machine
• This also means Docker is Linux-only; running
Docker on OSX and Windows requires a VM
VM-based Docker-based
Source: https://www.docker.com/whatisdocker/
Docker on OSX and Windows
• Use the official boot2docker application
• Convenience wrapper around VirtualBox
• Runs a Tiny Core Linux VM with Docker
• Docker client on host platform
communicates with the Docker daemon in
the VM via TCP
Kitematic GUI
• Recently acquired by Docker
• Also wraps VirtualBox
Docker Concepts
Images
• Images are indexed filesystem layers which
combine into a snapshot
• Every additional layer creates a new image
• Many images can share the same base
• Docker provides image management and
distribution
• Docker Hub is a central repository for
uploading and downloading shared images
Source: https://docs.docker.com/terms/layer
Containers
• Runtime instances of images
• Spawn multiple containers from an image with
individual parameters
• When a container starts, it allocates and isolates
resources (filesystem, network, etc) and executes its
process as PID 1 in this environment
• Containers will retain filesystem changes in a new
read-write layer
• Changes to a container can be persisted to a new
image using docker commit
Volumes
• Mount external directories from the host
machine
• Can be a bind mount or a volume attached to
a container; the latter allows you to reference
volumes from other containers
• Typically used to share and persist runtime
data across containers
• Volumes are local to the host machine; they
cannot be distributed like images
The Docker Binary
• Daemon and client rolled into one
• The client makes RPC calls to the daemon
• The daemon creates containers as child
processes
• Rocket, an alternative container spec from
CoreOS, delegates this role to systemd
docker push
docker pull
registry
FROM debian:wheezy
MAINTAINER blah <me@blah.co>
RUN apt-get install rabbitmq-server
EXPOSE 5672 15672
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/usr/sbin/rabbitmq-server"]
Dockerfile
docker build
docker tag
image
docker run
container
docker commit
Dockerfiles
Dockerfile format
• Plain text file
• Consists of a series of commands
• Each command creates a new image layer

• FROM - specify the base image tag to build upon
• MAINTAINER - tag the image with name and email
• ENV - set environment flags for subsequent commands
• ADD - copy files, directories, archives, remote urls, etc into the image
• COPY - same as above but without archive or remote url handling
• RUN - execute a command and persist the results as another layer
• EXPOSE - declare TCP or UDP port forwarding
• ENTRYPOINT - specify the process to run as PID 1 (default is /bin/sh -c)
• CMD - argument(s) to pass to entrypoint
Sample Dockerfile
FROM debian:wheezy
MAINTAINER Pie <foobar@pie.co>
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y curl wget php-fpm
RUN apt-get clean
RUN rm -rf /tmp/* /var/tmp/*
RUN rm -rf /var/lib/apt/lists/*
ENV DEBIAN_FRONTEND newt
Sample Dockerfile
FROM debian:wheezy
MAINTAINER Pie <foobar@pie.co>
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update 
&& apt-get install -y curl wget php-fpm 
&& apt-get clean 
&& rm -rf /tmp/* /var/tmp/* 
&& rm -rf /var/lib/apt/lists/*
ENV DEBIAN_FRONTEND newt
Sample Dockerfile
FROM debian:wheezy
MAINTAINER Pie <foobar@pie.co>
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive
ADD . /build
RUN /build/scripts/environment.sh 
&& /build/scripts/services.sh 
&& /build/scripts/cleanup.sh
ENV DEBIAN_FRONTEND newt
• Create the image from a Dockerfile in the cwd:
docker build -t pie/base .
• A container spawned from this image will
terminate immediately since there is no command
to run (implicit /bin/sh -c)
• We can pass in a command:
docker run pie/base echo 'hi'
• This container terminates with output
• Stopped containers remain listed in docker ps -a
• To clean up after running:
docker run --rm pie/base echo 'hi'
• Inspect the image:
docker inspect pie/base
• You can also view the history (all image layers and their
respective sizes)
docker history pie/base
• Run a container as a background process:
docker run -d --name hi pie/base /bin/sh
-c “while true;do echo 'hi';sleep 1;done”
• View the logs of a running container:
docker logs hi
• “Log into” a running container:
docker exec -it hi /bin/sh
Defining the process
FROM pieco/base:latest
MAINTAINER Pie <foobar@pie.co>
RUN apt-get install rabbitmq-server 
&& rabbitmq-plugins enable
rabbitmq_management
EXPOSE 5672 15672
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/usr/sbin/rabbitmq-server"]
• Since the process daemonizes, the container
will remain running.
docker run -d --name rabbitmq
pie/rabbitmq
• Find out which ports are exposed:
docker port rabbitmq
15672/tcp -> 0.0.0.0:15672
5672/tcp -> 0.0.0.0:5672
• Now you can interact over TCP:
curl -u guest:guest

"http://192.168.59.103:15672/api/..."
{"status":"ok"}
• You can map to different ports:
docker run -d --name rabbitmq

-p 8080:15672 -p 8081:5672

pie/rabbitmq
• Now:
docker port rabbitmq
15672/tcp -> 0.0.0.0:8080
5672/tcp -> 0.0.0.0:8081
• You can also use -P to map all exposed
ports to random ports (49153 to 65535)
Tips and Tricks
Scripts vs daemons
• Distinguish between short-lived and long-running
containers
• You can use containers like simple binaries
• e.g. docker run --rm -v $(pwd):/opt pie/git clone
git@github.com:pie/foobar.git /opt/foobar
• This clones a repository into your current directory
using a container with git installed
• Chain several specialised containers to form your
build system (e.g. Composer, gulp, etc)
• Load the compiled app into your runtime container
Getting files in and out
• Host <=> container: Use a bind mount
docker run -it -v $(pwd):/opt <image> /bin/sh
• Or pipe your files in:
tar cz - . | docker run -i <image> tar xz -C /opt
• Cross-container: Named volumes
docker run -v /opt --name data <image> /bin/true
docker run -it --volumes-from data <image> /bin/sh
• Container => host: Use docker cp
docker cp <container>:/opt/* .
• Image => host: Use a bind mount
docker run --rm -v $(pwd):/tmp <image> /bin/sh -c
'cp -rf /opt /tmp'
Logging and monitoring
• Similar to how you dockerize your apps, you
can also dockerize your logging and
monitoring processes
• Docker provides APIs to collect container
events, output and resource stats
• Use metrics and logging containers that take
advantage of this feature
• Some examples: gliderlabs/logspout,
datadog/docker-dd-agent
Beware the cargo cult
• You don’t have to dockerize everything
• You don’t necessarily need an init system;
use for legacy apps (e.g. needs cron)
• Don’t install dependencies and utilities you
don’t need (e.g. sshd)
• Explore using lean base images, you don’t
need Ubuntu to run a PHP/Node/Golang app
Demo
Thank you
kuanyen@pie.co
https://github.com/gigablah
@gigablah

Contenu connexe

Tendances

Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Introduction to Docker at SF Peninsula Software Development Meetup @GuidewireIntroduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Introduction to Docker at SF Peninsula Software Development Meetup @GuidewiredotCloud
 
Adventures in docker compose
Adventures in docker composeAdventures in docker compose
Adventures in docker composeLinkMe Srl
 
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 DeploymentsBen Hall
 
Rapid Development With Docker Compose
Rapid Development With Docker ComposeRapid Development With Docker Compose
Rapid Development With Docker ComposeJustin Crown
 
Docker Introductory workshop
Docker Introductory workshopDocker Introductory workshop
Docker Introductory workshopRuncy Oommen
 
Containerization and Docker
Containerization and DockerContainerization and Docker
Containerization and DockerMegha Bansal
 
Docker Distributed application bundle & Stack - Overview
Docker Distributed application bundle & Stack - Overview Docker Distributed application bundle & Stack - Overview
Docker Distributed application bundle & Stack - Overview Thomas Chacko
 
Docker with openstack
Docker with openstackDocker with openstack
Docker with openstackLiang Bo
 
GDG Lima - Docker Compose
GDG Lima - Docker ComposeGDG Lima - Docker Compose
GDG Lima - Docker ComposeMario IC
 
Hands-On Session Docker
Hands-On Session DockerHands-On Session Docker
Hands-On Session DockerLinetsChile
 
Optimizing Docker Images
Optimizing Docker ImagesOptimizing Docker Images
Optimizing Docker ImagesBrian DeHamer
 
Intro- Docker Native for OSX and Windows
Intro- Docker Native for OSX and WindowsIntro- Docker Native for OSX and Windows
Intro- Docker Native for OSX and WindowsThomas Chacko
 

Tendances (20)

Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Introduction to Docker at SF Peninsula Software Development Meetup @GuidewireIntroduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
 
Adventures in docker compose
Adventures in docker composeAdventures in docker compose
Adventures in docker compose
 
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
 
Docker
DockerDocker
Docker
 
Rapid Development With Docker Compose
Rapid Development With Docker ComposeRapid Development With Docker Compose
Rapid Development With Docker Compose
 
Docker Introductory workshop
Docker Introductory workshopDocker Introductory workshop
Docker Introductory workshop
 
Containerization and Docker
Containerization and DockerContainerization and Docker
Containerization and Docker
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
Docker Distributed application bundle & Stack - Overview
Docker Distributed application bundle & Stack - Overview Docker Distributed application bundle & Stack - Overview
Docker Distributed application bundle & Stack - Overview
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
 
Docker Support
Docker Support Docker Support
Docker Support
 
Docker with openstack
Docker with openstackDocker with openstack
Docker with openstack
 
Docker Workshop
Docker WorkshopDocker Workshop
Docker Workshop
 
GDG Lima - Docker Compose
GDG Lima - Docker ComposeGDG Lima - Docker Compose
GDG Lima - Docker Compose
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
Hands-On Session Docker
Hands-On Session DockerHands-On Session Docker
Hands-On Session Docker
 
Optimizing Docker Images
Optimizing Docker ImagesOptimizing Docker Images
Optimizing Docker Images
 
Intro- Docker Native for OSX and Windows
Intro- Docker Native for OSX and WindowsIntro- Docker Native for OSX and Windows
Intro- Docker Native for OSX and Windows
 
Docker
DockerDocker
Docker
 
Docker
DockerDocker
Docker
 

Similaire à Introduction to Docker

Getting Started with Docker
Getting Started with DockerGetting Started with Docker
Getting Started with DockerGeeta Vinnakota
 
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 ContainerGuido Schmutz
 
Virtualization, Containers, Docker and scalable container management services
Virtualization, Containers, Docker and scalable container management servicesVirtualization, Containers, Docker and scalable container management services
Virtualization, Containers, Docker and scalable container management servicesabhishek chawla
 
Savosyuk Stanislav "Docker: Not to Be Confused with a Blue Whale"
Savosyuk Stanislav "Docker: Not to Be Confused with a Blue Whale"Savosyuk Stanislav "Docker: Not to Be Confused with a Blue Whale"
Savosyuk Stanislav "Docker: Not to Be Confused with a Blue Whale"LogeekNightUkraine
 
Docker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken CochraneDocker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken CochranedotCloud
 
Docker for the new Era: Introducing Docker,its components and tools
Docker for the new Era: Introducing Docker,its components and toolsDocker for the new Era: Introducing Docker,its components and tools
Docker for the new Era: Introducing Docker,its components and toolsRamit Surana
 
IBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and DockerIBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and DockerDavid Currie
 
Getting started with Docker
Getting started with DockerGetting started with Docker
Getting started with DockerRavindu Fernando
 
Containerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and JavaContainerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and JavaJadson Santos
 
Up and running with docker
Up and running with dockerUp and running with docker
Up and running with dockerMichelle Liu
 
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Binary Studio
 

Similaire à Introduction to Docker (20)

Docker presentation
Docker presentationDocker presentation
Docker presentation
 
Getting Started with Docker
Getting Started with DockerGetting Started with Docker
Getting Started with Docker
 
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
 
Virtualization, Containers, Docker and scalable container management services
Virtualization, Containers, Docker and scalable container management servicesVirtualization, Containers, Docker and scalable container management services
Virtualization, Containers, Docker and scalable container management services
 
Docker, LinuX Container
Docker, LinuX ContainerDocker, LinuX Container
Docker, LinuX Container
 
Docker From Scratch
Docker From ScratchDocker From Scratch
Docker From Scratch
 
Docker, but what it is?
Docker, but what it is?Docker, but what it is?
Docker, but what it is?
 
Savosyuk Stanislav "Docker: Not to Be Confused with a Blue Whale"
Savosyuk Stanislav "Docker: Not to Be Confused with a Blue Whale"Savosyuk Stanislav "Docker: Not to Be Confused with a Blue Whale"
Savosyuk Stanislav "Docker: Not to Be Confused with a Blue Whale"
 
Docker
DockerDocker
Docker
 
Django and Docker
Django and DockerDjango and Docker
Django and Docker
 
Docker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken CochraneDocker at Djangocon 2013 | Talk by Ken Cochrane
Docker at Djangocon 2013 | Talk by Ken Cochrane
 
Docker for the new Era: Introducing Docker,its components and tools
Docker for the new Era: Introducing Docker,its components and toolsDocker for the new Era: Introducing Docker,its components and tools
Docker for the new Era: Introducing Docker,its components and tools
 
Containerization using docker and its applications
Containerization using docker and its applicationsContainerization using docker and its applications
Containerization using docker and its applications
 
Containerization using docker and its applications
Containerization using docker and its applicationsContainerization using docker and its applications
Containerization using docker and its applications
 
IBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and DockerIBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and Docker
 
Docker
DockerDocker
Docker
 
Getting started with Docker
Getting started with DockerGetting started with Docker
Getting started with Docker
 
Containerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and JavaContainerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and Java
 
Up and running with docker
Up and running with dockerUp and running with docker
Up and running with docker
 
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2
 

Dernier

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Dernier (20)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

Introduction to Docker

  • 1. Introduction to Docker SG PHP Meetup March 2015
  • 2. About me • Kuan-Yen Heng (Chris) • Software Engineer at Pie • kuanyen@pie.co • https://github.com/gigablah • @gigablah
  • 4. What’s Docker? • Abstraction layer for Linux containers • Written in Google Go (golang) • Started as an internal project in dotCloud, a PaaS company • Open sourced in Mar 2013 • dotCloud pivots and becomes Docker, Inc • Docker Machine, Swarm and Compose announced in Dec 2014
  • 5. Why Docker? • Lightweight resource usage • Extremely fast startup compared to VMs • Repeatable, consistent builds (if careful) • Dependency isolation • Pristine host OS; only Docker needs to be installed (easier updates)
  • 6. Why Docker? • If you want to… • Upgrade PHP for an app but you have an old vBulletin installation that needs PHP 5.3 • Run Python 2.7 and Python 3 apps • Switch your OS entirely • Get the same image to run on your laptop, your CI service, staging and production without having to “bake” different image formats • Docker makes it relatively painless
  • 7. Vagrant vs. Docker • Vagrant is an abstraction layer for VMs • Each VM is a system in its own right (allocated resources, virtualised hardware) • Docker containers, however, all make use of the same underlying host kernel • Processes in Docker run as regular processes on the host machine • This also means Docker is Linux-only; running Docker on OSX and Windows requires a VM
  • 9. Docker on OSX and Windows • Use the official boot2docker application • Convenience wrapper around VirtualBox • Runs a Tiny Core Linux VM with Docker • Docker client on host platform communicates with the Docker daemon in the VM via TCP
  • 10. Kitematic GUI • Recently acquired by Docker • Also wraps VirtualBox
  • 12. Images • Images are indexed filesystem layers which combine into a snapshot • Every additional layer creates a new image • Many images can share the same base • Docker provides image management and distribution • Docker Hub is a central repository for uploading and downloading shared images
  • 14. Containers • Runtime instances of images • Spawn multiple containers from an image with individual parameters • When a container starts, it allocates and isolates resources (filesystem, network, etc) and executes its process as PID 1 in this environment • Containers will retain filesystem changes in a new read-write layer • Changes to a container can be persisted to a new image using docker commit
  • 15. Volumes • Mount external directories from the host machine • Can be a bind mount or a volume attached to a container; the latter allows you to reference volumes from other containers • Typically used to share and persist runtime data across containers • Volumes are local to the host machine; they cannot be distributed like images
  • 16. The Docker Binary • Daemon and client rolled into one • The client makes RPC calls to the daemon • The daemon creates containers as child processes • Rocket, an alternative container spec from CoreOS, delegates this role to systemd
  • 17. docker push docker pull registry FROM debian:wheezy MAINTAINER blah <me@blah.co> RUN apt-get install rabbitmq-server EXPOSE 5672 15672 ENTRYPOINT ["/bin/bash", "-c"] CMD ["/usr/sbin/rabbitmq-server"] Dockerfile docker build docker tag image docker run container docker commit
  • 19. Dockerfile format • Plain text file • Consists of a series of commands • Each command creates a new image layer
 • FROM - specify the base image tag to build upon • MAINTAINER - tag the image with name and email • ENV - set environment flags for subsequent commands • ADD - copy files, directories, archives, remote urls, etc into the image • COPY - same as above but without archive or remote url handling • RUN - execute a command and persist the results as another layer • EXPOSE - declare TCP or UDP port forwarding • ENTRYPOINT - specify the process to run as PID 1 (default is /bin/sh -c) • CMD - argument(s) to pass to entrypoint
  • 20. Sample Dockerfile FROM debian:wheezy MAINTAINER Pie <foobar@pie.co> ENV LC_ALL C ENV DEBIAN_FRONTEND noninteractive RUN apt-get update RUN apt-get install -y curl wget php-fpm RUN apt-get clean RUN rm -rf /tmp/* /var/tmp/* RUN rm -rf /var/lib/apt/lists/* ENV DEBIAN_FRONTEND newt
  • 21. Sample Dockerfile FROM debian:wheezy MAINTAINER Pie <foobar@pie.co> ENV LC_ALL C ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && apt-get install -y curl wget php-fpm && apt-get clean && rm -rf /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/* ENV DEBIAN_FRONTEND newt
  • 22. Sample Dockerfile FROM debian:wheezy MAINTAINER Pie <foobar@pie.co> ENV LC_ALL C ENV DEBIAN_FRONTEND noninteractive ADD . /build RUN /build/scripts/environment.sh && /build/scripts/services.sh && /build/scripts/cleanup.sh ENV DEBIAN_FRONTEND newt
  • 23. • Create the image from a Dockerfile in the cwd: docker build -t pie/base . • A container spawned from this image will terminate immediately since there is no command to run (implicit /bin/sh -c) • We can pass in a command: docker run pie/base echo 'hi' • This container terminates with output • Stopped containers remain listed in docker ps -a • To clean up after running: docker run --rm pie/base echo 'hi'
  • 24. • Inspect the image: docker inspect pie/base • You can also view the history (all image layers and their respective sizes) docker history pie/base • Run a container as a background process: docker run -d --name hi pie/base /bin/sh -c “while true;do echo 'hi';sleep 1;done” • View the logs of a running container: docker logs hi • “Log into” a running container: docker exec -it hi /bin/sh
  • 25. Defining the process FROM pieco/base:latest MAINTAINER Pie <foobar@pie.co> RUN apt-get install rabbitmq-server && rabbitmq-plugins enable rabbitmq_management EXPOSE 5672 15672 ENTRYPOINT ["/bin/bash", "-c"] CMD ["/usr/sbin/rabbitmq-server"]
  • 26. • Since the process daemonizes, the container will remain running. docker run -d --name rabbitmq pie/rabbitmq • Find out which ports are exposed: docker port rabbitmq 15672/tcp -> 0.0.0.0:15672 5672/tcp -> 0.0.0.0:5672 • Now you can interact over TCP: curl -u guest:guest
 "http://192.168.59.103:15672/api/..." {"status":"ok"}
  • 27. • You can map to different ports: docker run -d --name rabbitmq
 -p 8080:15672 -p 8081:5672
 pie/rabbitmq • Now: docker port rabbitmq 15672/tcp -> 0.0.0.0:8080 5672/tcp -> 0.0.0.0:8081 • You can also use -P to map all exposed ports to random ports (49153 to 65535)
  • 29. Scripts vs daemons • Distinguish between short-lived and long-running containers • You can use containers like simple binaries • e.g. docker run --rm -v $(pwd):/opt pie/git clone git@github.com:pie/foobar.git /opt/foobar • This clones a repository into your current directory using a container with git installed • Chain several specialised containers to form your build system (e.g. Composer, gulp, etc) • Load the compiled app into your runtime container
  • 30. Getting files in and out • Host <=> container: Use a bind mount docker run -it -v $(pwd):/opt <image> /bin/sh • Or pipe your files in: tar cz - . | docker run -i <image> tar xz -C /opt • Cross-container: Named volumes docker run -v /opt --name data <image> /bin/true docker run -it --volumes-from data <image> /bin/sh • Container => host: Use docker cp docker cp <container>:/opt/* . • Image => host: Use a bind mount docker run --rm -v $(pwd):/tmp <image> /bin/sh -c 'cp -rf /opt /tmp'
  • 31. Logging and monitoring • Similar to how you dockerize your apps, you can also dockerize your logging and monitoring processes • Docker provides APIs to collect container events, output and resource stats • Use metrics and logging containers that take advantage of this feature • Some examples: gliderlabs/logspout, datadog/docker-dd-agent
  • 32. Beware the cargo cult • You don’t have to dockerize everything • You don’t necessarily need an init system; use for legacy apps (e.g. needs cron) • Don’t install dependencies and utilities you don’t need (e.g. sshd) • Explore using lean base images, you don’t need Ubuntu to run a PHP/Node/Golang app
  • 33. Demo