Tải bản đầy đủ (.pdf) (547 trang)

Learn docker fundamentals of docker 18xEverything you need to know about containerizing your applications and running them in production

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (22.04 MB, 547 trang )


LearnDocker–FundamentalsofDocker18.x



Everythingyouneedtoknowaboutcontainerizingyourapplicationsandrunning
theminproduction







GabrielN.Schenker












BIRMINGHAM-MUMBAI


LearnDocker–Fundamentalsof


Docker18.x
Copyright©2018PacktPublishing
Allrightsreserved.Nopartofthisbookmaybereproduced,storedinaretrievalsystem,ortransmittedin
anyformorbyanymeans,withoutthepriorwrittenpermissionofthepublisher,exceptinthecaseofbrief
quotationsembeddedincriticalarticlesorreviews.
Everyefforthasbeenmadeinthepreparationofthisbooktoensuretheaccuracyoftheinformation
presented.However,theinformationcontainedinthisbookissoldwithoutwarranty,eitherexpressor
implied.Neithertheauthor,norPacktPublishingoritsdealersanddistributors,willbeheldliableforany
damagescausedorallegedtohavebeencauseddirectlyorindirectlybythisbook.
PacktPublishinghasendeavoredtoprovidetrademarkinformationaboutallofthecompaniesandproducts
mentionedinthisbookbytheappropriateuseofcapitals.However,PacktPublishingcannotguaranteethe
accuracyofthisinformation.
CommissioningEditor:GebinGeorge
AcquisitionEditor:ShrilekhaInani
ContentDevelopmentEditor:RonnKurien
TechnicalEditor:SwathyMohan
CopyEditor:SafisEditing
ProjectCoordinator:JudieJose
Proofreader:SafisEditing
Indexer:PriyankaDhadke
Graphics:TomScaria
ProductionCoordinator:NileshMohite
Firstpublished:April2018
Productionreference:1240418
PublishedbyPacktPublishingLtd.
LiveryPlace
35LiveryStreet
Birmingham
B32PB,UK.
ISBN978-1-78899-702-7

www.packtpub.com


mapt.io

Maptisanonlinedigitallibrarythatgivesyoufullaccesstoover5,000books
andvideos,aswellasindustryleadingtoolstohelpyouplanyourpersonal
developmentandadvanceyourcareer.Formoreinformation,pleasevisitour
website.


Whysubscribe?
SpendlesstimelearningandmoretimecodingwithpracticaleBooksand
Videosfromover4,000industryprofessionals
ImproveyourlearningwithSkillPlansbuiltespeciallyforyou
GetafreeeBookorvideoeverymonth
Maptisfullysearchable
Copyandpaste,print,andbookmarkcontent


PacktPub.com
DidyouknowthatPacktofferseBookversionsofeverybookpublished,with
PDFandePubfilesavailable?YoucanupgradetotheeBookversionatwww.PacktP
ub.comandasaprintbookcustomer,youareentitledtoadiscountontheeBook
copy.Getintouchwithusatservice@packtpub.comformoredetails.
Atwww.PacktPub.com,youcanalsoreadacollectionoffreetechnicalarticles,sign
upforarangeoffreenewsletters,andreceiveexclusivediscountsandofferson
PacktbooksandeBooks.



Contributors


Abouttheauthor
GabrielN.Schenkerhasmorethan25yearsofexperienceasanindependent
consultant,architect,leader,trainer,mentor,anddeveloper.Currently,Gabriel
worksasSeniorCurriculumDeveloperatConfluentaftercomingfromasimilar
positionatDocker.GabrielhasaPh.D.inPhysics,andheisaDockerCaptain,a
CertifiedDockerAssociate,andanASPInsider.Whennotworking,Gabriel
enjoystimewithhiswonderfulwifeVeronicahandhischildren.




Aboutthereviewer
PeterMcKeeisaSoftwareArchitectandSeniorSoftwareEngineeratDocker,
Inc.HeleadsthetechnicalteamthatdeliverstheDockerSuccessCenter.He's
beenleadingandmentoringteamsformorethan20years.Whennotbuilding
thingswithsoftware,hespendshistimewithhiswifeandsevenkidsinbeautiful
Austin,TX.



Packtissearchingforauthorslike
you
Ifyou'reinterestedinbecominganauthorforPackt,pleasevisitauthors.packtpub.c
omandapplytoday.Wehaveworkedwiththousandsofdevelopersandtech
professionals,justlikeyou,tohelpthemsharetheirinsightwiththeglobaltech
community.Youcanmakeageneralapplication,applyforaspecifichottopic
thatwearerecruitinganauthorfor,orsubmityourownidea.



TableofContents


TitlePage
CopyrightandCredits
LearnDocker–FundamentalsofDocker18.x
PacktUpsell
Whysubscribe?
PacktPub.com
Contributors
Abouttheauthor
Aboutthereviewer
Packtissearchingforauthorslikeyou
Preface
Whothisbookisfor
Whatthisbookcovers
Togetthemostoutofthisbook
Downloadtheexamplecodefiles
Downloadthecolorimages
Conventionsused
Getintouch
Reviews

1.

WhatAreContainersandWhyShouldIUseThem?
Technicalrequirements
Whatarecontainers?

Whyarecontainersimportant?
What'sthebenefitformeorformycompany?
TheMobyproject
Dockerproducts
DockerCE
DockerEE
Thecontainerecosystem
Containerarchitecture
Summary
Questions
Furtherreading


2.

SettingupaWorkingEnvironment
Technicalrequirements
TheLinuxcommandshell
PowerShellforWindows
Usingapackagemanager
InstallingHomebrewonaMac
InstallingChocolateyonWindows
Choosingacodeeditor
DockerToolbox
DockerforMacandDockerforWindows
InstallingDockerforMac
InstallingDockerforWindows
Usingdocker-machineonWindowswithHyper-V
Minikube
InstallingMinikubeon MacandWindows

TestingMinikubeandkubectl
Summary
Questions
Furtherreading


3.

WorkingwithContainers
Technicalrequirements
Runningthefirstcontainer
Starting,stopping,andremovingcontainers
Runningarandomquotescontainer
Listingcontainers
Stoppingandstartingcontainers
Removingcontainers
Inspectingcontainers
Execintoarunningcontainer
Attachingtoarunningcontainer
Retrievingcontainerlogs
Loggingdrivers
Usingacontainer-specificloggingdriver
Advancedtopic–changingthedefaultloggingdriver
Anatomyofcontainers
Architecture
Namespaces
Controlgroups(cgroups)
Unionfilesystem(UnionFS)
Containerplumbing
Runc

Containerd
Summary
Questions
Furtherreading


4.

CreatingandManagingContainerImages
Whatareimages?
Thelayeredfilesystem
Thewritablecontainerlayer
Copy-on-write
Graphdrivers
Creatingimages
Interactiveimagecreation
UsingDockerfiles
TheFROMkeyword
TheRUNkeyword
TheCOPYandADDkeywords
TheWORKDIRkeyword
TheCMDandENTRYPOINTkeywords
AcomplexDockerfile
Buildinganimage
Multistepbuilds
Dockerfilebestpractices
Savingandloadingimages
Sharingorshippingimages
Tagginganimage
Imagenamespaces

Officialimages
Pushingimagestoaregistry
Summary
Questions
Furtherreading


5.

DataVolumesandSystemManagement
Technicalrequirements
Creatingandmountingdatavolumes
Modifyingthecontainerlayer
Creatingvolumes
Mountingavolume
Removingvolumes
Sharingdatabetweencontainers
Usinghostvolumes
Definingvolumesinimages
ObtainingDockersysteminformation
Listingresourceconsumption
Pruningunusedresources
Pruningcontainers
Pruningimages
Pruningvolumes
Pruningnetworks
Pruningeverything
ConsumingDockersystemevents
Summary
Questions

Furtherreading


6.

DistributedApplicationArchitecture
Whatisadistributedapplicationarchitecture?
Definingtheterminology
Patternsandbestpractices
Looselycoupledcomponents
Statefulversusstateless
Servicediscovery
Routing
Loadbalancing
Defensiveprogramming
Retries
Logging
Errorhandling
Redundancy
Healthchecks
Circuitbreakerpattern
Runninginproduction
Logging
Tracing
Monitoring
Applicationupdates
Rollingupdates
Blue-greendeployments
Canaryreleases
Irreversibledatachanges

Rollback
Summary
Questions
Furtherreading


7.

Single-HostNetworking
Technicalrequirements
Thecontainernetworkmodel
Networkfirewalling
Thebridgenetwork
Thehostnetwork
Thenullnetwork
Runninginanexistingnetworknamespace
Portmanagement
Summary
Questions
Furtherreading


8.

DockerCompose
Technicalrequirements
Demystifyingdeclarativeversusimperative
Runningamulti-serviceapp
Scalingaservice
Buildingandpushinganapplication

Summary
Questions
Furtherreading


9.

Orchestrators
Whatareorchestratorsandwhydoweneedthem?
Thetasksofanorchestrator
Reconcilingthedesiredstate
Replicatedandglobalservices
Servicediscovery
Routing
Loadbalancing
Scaling
Self-healing
Zerodowntimedeployments
Affinityandlocationawareness
Security
Securecommunicationandcryptographicnodeidentity
Securenetworksandnetworkpolicies
Role-basedaccesscontrol(RBAC)
Secrets
Contenttrust
Reverseuptime
Introspection
Overviewofpopularorchestrators
Kubernetes
DockerSwarm

ApacheMesosandMarathon
AmazonECS
MicrosoftACS 
Summary
Questions
Furtherreading


10.

IntroductiontoDockerSwarm
Architecture
Swarmnodes
Swarmmanagers
Swarmworkers  
Stacks,services,andtasks
Services
Task
Stack
Multi-hostnetworking
CreatingaDockerSwarm
Creatingalocalsinglenodeswarm
CreatingalocalswarminVirtualBoxorHyper-V
UsingPlaywithDocker(PWD)togenerateaSwarm
CreatingaDockerSwarminthecloud
Deployingafirstapplication
Creatingaservice
Inspectingtheserviceanditstasks
Logsofaservice
Reconcilingthedesiredstate

Deletingaserviceorastack
Deployingamulti-servicestack
Theswarmroutingmesh
Summary
Questions
Furtherreading


11.

ZeroDowntimeDeploymentsandSecrets
Technicalrequirements
Zerodowntimedeployment
Populardeploymentstrategies
Rollingupdates
Healthchecks
Rollback
Blue–greendeployments
Canaryreleases
Secrets
Creatingsecrets
Usingasecret
Simulatingsecretsinadevelopmentenvironment
Secretsandlegacyapplications
Updatingsecrets
Summary
Questions
Furtherreading



12.

IntroductiontoKubernetes
Technicalrequirements
Architecture
Kubernetesmasternodes
Clusternodes
IntroductiontoMinikube
KubernetessupportinDockerforDesktop
Pods
ComparingDockercontainerandKubernetespodnetworking
Sharingthenetworknamespace
Podlifecycle
Podspecification
Podsandvolumes
KubernetesReplicaSet
ReplicaSetspecification
Self-healing
Kubernetesdeployment
Kubernetesservice
Context-basedrouting
ComparingSwarmKitwithKubernetes
Summary
Questions
Furtherreading


13.

Deploying,Updating,andSecuringanApplicationwithKubernetes

Technicalrequirements
Deployingafirstapplication
Deployingthewebcomponent
Deployingthedatabase
Streamliningthedeployment
Zerodowntimedeployments
Rollingupdates
Blue–greendeployment
Kubernetessecrets
Manuallydefiningsecrets
Creatingsecretswithkubectl
Usingsecretsinapod
Secretvaluesinenvironmentvariables
Summary
Questions
Furtherreading


×