Ebooks File Docker in Practice 1st Edition Ian Miell All Chapters
Ebooks File Docker in Practice 1st Edition Ian Miell All Chapters
com
https://textbookfull.com/product/docker-in-
practice-1st-edition-ian-miell/
https://textbookfull.com/product/docker-in-action-1st-edition-jeff-
nickoloff/
textbookfull.com
https://textbookfull.com/product/learn-docker-in-a-month-of-
lunches-1st-edition-elton-stoneman/
textbookfull.com
https://textbookfull.com/product/the-great-demographic-reversal-
ageing-societies-waning-inequality-and-an-inflation-revival-charles-
goodhart-2/
textbookfull.com
Empirical Philosophical Investigations in Education and
Embodied Experience Joacim Andersson
https://textbookfull.com/product/empirical-philosophical-
investigations-in-education-and-embodied-experience-joacim-andersson/
textbookfull.com
https://textbookfull.com/product/banking-reforms-in-india-
consolidation-restructuring-and-performance-1st-edition-t-r-bishnoi/
textbookfull.com
https://textbookfull.com/product/financial-institutions-and-markets-
structure-growth-and-innovations-6th-edition-jitendra-mahakud/
textbookfull.com
https://textbookfull.com/product/collective-actions-in-europe-a-
comparative-economic-and-transsystemic-analysis-csongor-istvan-nagy/
textbookfull.com
https://textbookfull.com/product/local-government-in-england-
centralisation-autonomy-and-control-1st-edition-colin-copus/
textbookfull.com
IN PRACTICE
Ian Miell
Aidan Hobson Sayers
FOREWORD BY Ben Firshman
MANNING
Docker in Practice
Docker in Practice
IAN MIELL
AIDAN HOBSON SAYERS
MANNING
SHELTER ISLAND
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: [email protected]
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books are
printed on paper that is at least 15 percent recycled and processed without the use of elemental
chlorine.
ISBN 9781617292729
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – EBM – 21 20 19 18 17 16
brief contents
PART 1 DOCKER FUNDAMENTALS ....................................................1
1 ■ Discovering Docker 3
2 ■ Understanding Docker—inside the engine room 19
v
vi BRIEF CONTENTS
1 Discovering Docker
1.1
3
The what and why of Docker 5
What is Docker? 5 ■
What is Docker good for? 7 ■
Key
concepts 8
1.2 Building a Docker application 10
Ways to create a new Docker image 11 Writing a Dockerfile 12
■
Docker layering 16
1.3 Summary 18
vii
viii CONTENTS
4 Day-to-day Docker 65
4.1 Volumes—a persistent problem 66
TECHNIQUE 19 Docker volumes—problems of persistence 66
TECHNIQUE 20 Distributed volumes with BitTorrent Sync 67
CONTENTS ix
xv
xvi FOREWORD
When I first saw Solomon Hykes, creator of Docker, talking about Docker and its
analogy to the shipping container, I knew he was on to something big. The complex
state of the worldwide shipping industry before standardization is an apt analogy for the
complex state of managing software before containers. Solomon’s insight was so con-
vincing that I started a company building tools around Docker, which was eventually
acquired by Docker, Inc. and turned into what we now know as Docker Compose.
I first met Ian at some of the Docker meetups we organized in London. Back then,
we insistently said, “Docker is not ready for production; please don’t use it!” but Ian
was the sort of person who would disregard this sensible advice and go ahead and run
it in production anyway. Back then, he was working for the betting services company
OpenBet alongside Aidan, and the amount of money they must have been processing
with the code we had at that time makes me feel a bit light-headed.
Ian and Aidan both saw that the value they got from using Docker outweighed the
inconveniences of working with it in its beta state. They jumped on the technology
early, and therefore have a unique perspective on how best to apply it. The tooling
they built at OpenBet has pointed out stuff that was missing in Docker, and our infor-
mal chats have had a real influence on the design and direction we’ve taken it.
Docker has moved along quite a bit since Ian and Aidan first started using it, and
thousands of organizations are now using it to solve real problems: shipping software
faster, managing its daunting complexity, improving the efficiency of infrastructure,
fixing “works on my machine” problems, and so on. This is causing a huge shift in how
we build, deploy, and manage software, and a whole new landscape of tools and ideas
is forming around it. The bright future of containerization is exciting, but is also
intimidatingly different from what we are used to.
For you, it might be hard to see how to get from here to there, but this book con-
tains a deluge of practical advice about how to apply Docker to problems you’re hav-
ing right now. Follow this advice, and your organization will keep on moving quickly.
And—perhaps more importantly—building and deploying your applications will
become a lot more enjoyable.
BEN FIRSHMAN
DIRECTOR OF PRODUCT MANAGEMENT, DOCKER, INC.
COCREATOR OF DOCKER COMPOSE
preface
In September 2013, while browsing Hacker News, I stumbled across an article in Wired
about a new technology called “Docker.” 1 As I read it, I became increasingly excited as
I realized Docker’s revolutionary potential.
The company I’d worked at for over a decade was struggling to deliver software
quickly enough. Provisioning environments was a costly, time-consuming, manual,
and inelegant affair. Continuous integration was barely existent, and setting up devel-
opment environments was an exercise in patience. As my job title included the words
“DevOps Manager,” I was peculiarly motivated to solve these problems!
I recruited a couple of motivated coworkers (one of them now my coauthor) via a
company mailing list, and together our skunkworks team labored to turn a beta tool
into a business advantage, reducing the high costs of VMs and enabling new ways of
thinking about building and deploying software. We even built and open sourced an
automation tool (ShutIt) to suit our organization’s delivery needs.
Docker gave us a packaged and maintained tool that solved many problems that
would have been effectively insuperable had we taken it upon ourselves to solve them.
This was open source at its best, empowering us to take on a challenge using our spare
time, overcoming technical debt, and learning lessons daily. Lessons not only about
Docker, but about continuous integration, continuous delivery, packaging, automa-
tion, and how people respond to speedy and disruptive technological change.
1
http://www.wired.com/2013/09/docker/
xvii
xviii PREFACE
For us, Docker is a remarkably broad tool. Wherever you run software using Linux,
Docker can impact it. This makes writing a book on the subject challenging, because
the landscape is as broad as software itself. The task is made more onerous by the
extraordinary rate at which the Docker ecosystem is producing solutions to meet the
needs that emerge from such a fundamental change in software production. Over
time, the shape of problems and solutions became familiar to us, and in this book
we’ve endeavored to pass on this experience. This will enable you to figure out solu-
tions to your particular technical and business constraints.
When giving talks at meetups, we’re struck by how quickly Docker has become
effective within organizations willing to embrace it. This book mirrors how we used
Docker, going from our desktops, through the DevOps pipeline, and all the way to
production. As a consequence, this book is sometimes unorthodox, but as engineers
we believe that purity must sometimes give way to practicality, especially when it comes
to saving money! Everything in this book is based on real lessons from the field, and
we hope you benefit from our hard-won experience.
IAN MIELL
acknowledgments
This book couldn’t have been written without the support, sacrifice, and patience of
those closest to us. Special mention is due to Stephen Hazleton, whose tireless efforts
with us to make Docker useful for our customers informed much of the book’s contents.
Several Docker contributors and staff were kind enough to review the book at dif-
ferent stages and provided much useful feedback, including the following people who
read the book in manuscript form: Benoit Benedetti, Burkhard Nestmann, Chad
Davis, David Moravec, Ernesto Cárdenas Cangahuala, Fernando Rodrigues, José San
Leandro, Kirk Brattkus, Pethuru Raj, Scott Bates, Steven Lembark, Stuart Woodward,
Ticean Bennett, Valmiky Arquissandas, and Wil Moore III.
Finally, this book also owes a great deal to the Manning editorial team, who went
out of their way to push us into making the book not just good enough, but the best it
could be. We hope the pride they took in their work rubbed off on us.
Ian Miell To Sarah, Isaac, and Rachel for putting up with the late-night coding, a
father glued to a laptop screen, and the eternal “Docker this, Docker that, Docker
blah, blah,” and to my parents for encouraging me from an early age to question the
status quo. And buying me that Spectrum.
Aidan Hobson Sayers To Mona for the support and encouragement, my parents for
their wisdom and motivating words, and my coauthor for that fateful “Has anyone
tried this Docker thing?” e-mail.
xix
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
about this book
Docker is arguably the fastest-growing software project ever. Open sourced in March 2013,
by 2016 it had gained nearly 30,000 GitHub stars and over 7,500 forks. It has accepted sig-
nificant numbers of pull requests from the likes of Red Hat, IBM, Microsoft, Google, Cisco
and VMware.
Docker has hit this critical mass by responding to a critical need for many software
organizations: the ability to build software in an open and flexible way and then
deploy it reliably and consistently in different contexts. You don’t need to learn a new
programming language, buy expensive hardware, or do much in the way of installa-
tion or configuration to build, ship, and run applications portably.
Docker in Practice takes you through real-world examples of Docker usage using
techniques we’ve employed in various contexts. Where possible, we’ve tried to eluci-
date these techniques without requiring knowledge of other technologies before read-
ing. We’ve assumed the reader has an understanding of basic development techniques
and concepts such as the ability to develop some structured code, as well as some
awareness of software development and deployment processes. In addition, we’ve
assumed a knowledge of core source control ideas and a basic understanding of net-
work fundamentals such as TCP/IP, HTTP, and ports. Anything less mainstream is
explained as we go.
Starting with a rundown of Docker fundamentals in part one, in part two we focus
on using Docker in development on a single machine. In part three, we move on to
Docker usage within a DevOps pipeline, covering continuous integration, continuous
xx
ABOUT THIS BOOK xxi
delivery, and testing. The last part covers Docker in production, focusing on your
options relating to orchestration.
Docker is such a broad, flexible, and dynamic tool that keeping up with its fast-
evolving landscape is not for the faint-hearted. We’ve endeavored to give you an
understanding of critical concepts through real-world applications and examples,
with the aim of giving you the power to critically evaluate future tools and technolo-
gies within the Docker ecosystem with confidence. We’ve tried to make the book an
enjoyable tour of the many ways we’ve seen Docker make our lives easier and even
fun. Immersing ourselves in Docker has introduced us to many interesting software
techniques spanning the entire software life cycle in a stimulating way, and we hope
that this is an experience shared by the reader.
Roadmap
This book consists of 12 chapters divided into four parts.
Part 1 lays the groundwork for the rest of the book, introducing Docker and get-
ting you to run some basic Docker commands. In chapter 2 some time is spent getting
you familiar with Docker’s client-server architecture and how to debug it, which can
be useful for identifying issues with unconventional Docker setups.
Part 2 focuses on familiarization with Docker and getting the most out of Docker
on your own machine. An analogy with a concept you may be familiar with, virtual
machines, is used as the basis for chapter 3 to provide an introduction to Docker
use. Chapter 4 then details a number of Docker techniques we’ve found ourselves
using every day. The final chapter in this part explores the topic of building images
in more depth.
Part 3 begins by looking at uses of Docker in a DevOps context, from using it for
automation of software builds and tests to moving your built software to different
places. This part concludes with a chapter on the Docker virtual network, introduces
Docker Compose, and covers some more-advanced networking topics, like network
simulation and Docker network plugins.
Part 4 covers a number of topics for using Docker effectively in a production envi-
ronment. It begins with chapter 9, where we survey some of the most popular tools for
orchestrating containers and note what scenarios they tend to be used in. Chapter 10
addresses the important topic of security, explaining how to lock down processes run-
ning inside a container and how to restrict access to an externally exposed Docker
daemon. The final two chapters go into detail on some key practical information for
running Docker in production. Chapter 11 demonstrates how to apply classic sys-
admin knowledge in the context of containers, from logging to resource limits, while
chapter 12 looks at some problems you may encounter and provides steps for debug-
ging and resolution.
The appendixes contain details on installing, using, and configuring Docker in dif-
ferent ways, including inside a virtual machine and on Windows.
xxii ABOUT THIS BOOK
Code
The source code for all tools, applications, and Docker images created by the authors
for use in this book is available for download from the publisher’s website at www
.manning.com/books/docker-in-practice and also on GitHub under the docker-in-
practice organization: https://github.com/docker-in-practice/. Images on the Docker
Hub under the dockerinpractice user (https://hub.docker.com/u/dockerinpractice/)
are typically automated builds from one of the GitHub repositories. Where we’ve felt the
reader may be interested in further study of some source code behind a technique, a link
to the relevant repository has been inserted in the technique discussion.
A significant number of the code listings in the book illustrate a terminal session
for the reader to follow, along with corresponding output from commands. There are
a couple of things to note about these sessions.
Long terminal commands may use the shell line continuation character (\) to split
a command over multiple lines. Although this will work in your shell if you type it out,
you may also omit it and type the whole command on one line.
Where a section of output doesn’t provide extra useful information to a reader, it
may be omitted and an ellipsis ([...]) inserted in its place.
Author Online
Purchase of Docker in Practice includes free access to a private web forum run by
Manning Publications where you can make comments about the book, ask technical
questions, and receive help from the lead author and from other users. To access the
forum and subscribe to it, point your web browser to www.manning.com/books/
docker-in-practice. This page provides information on how to get on the forum once
you are registered, what kind of help is available, and the rules of conduct on the forum.
Manning’s commitment to our readers is to provide a venue where a meaningful
dialog between individual readers and between readers and the authors can take
place. It is not a commitment to any specific amount of participation on the part of
the authors, whose contribution to the forum remains voluntary (and unpaid). We
suggest you try asking their some challenging questions lest them interest stray! The
Author Online forum and the archives of previous discussions will be accessible from
the publisher’s website as long as the book is in print.
about the cover illustration
The figure on the cover of Docker in Practice is captioned “Man from Selce, Croatia.”
The illustration is taken from a reproduction of an album of Croatian traditional cos-
tumes from the mid-nineteenth century by Nikola Arsenovic, published by the Ethno-
graphic Museum in Split, Croatia, in 2003. The illustrations were obtained from a
helpful librarian at the Ethnographic Museum in Split, itself situated in the Roman
core of the medieval center of the town: the ruins of Emperor Diocletian’s retirement
palace from around AD 304. The book includes finely colored illustrations of figures
from different regions of Croatia, accompanied by descriptions of the costumes and
of everyday life.
Dress codes and lifestyles have changed over the last 200 years, and the diversity by
region, so rich at the time, has faded away. It’s now hard to tell apart the inhabitants of
different continents, let alone of different hamlets or towns separated by only a few
miles. Perhaps we have traded cultural diversity for a more varied personal life—
certainly for a more varied and fast-paced technological life.
Manning celebrates the inventiveness and initiative of the computer business with
book covers based on the rich diversity of regional life of two centuries ago, brought
back to life by illustrations from old books and collections like this one.
xxiii
Random documents with unrelated
content Scribd suggests to you:
— Sangen huonoa. Teidän pitäisikin poiketa sinne sisään näin
lähellä ollessanne, se varmaan ilahuttaisi häntä.
— Jos haluatte, herra Falk, niin käymme Pekan isän luona, hänen,
josta olen puhunut — sanoi Saara.
Samaa ei voinut sanoa papin kuvasta, jota hänen silloin tällöin väli
aikoina täytyi maalata. Pastori saattoi hänet epäilykseen. Ei yksistään
pitkät pöytärukoukset, aamu- ja iltasiunaukset häntä kiusanneet,
vaan hänen oli mahdotoin saada pappia luonnolliseen asentoon. Hän
tahtoi ehdottomasti pitää kätensä ristissä vatsalla ja joka kerta kun
maalari katsoi häneen kuvataksensa uuden piirteen asetti hän
päänsä vinoon ja loi silmänsä korkeuteen. Se näytti aikalailla
teeskennellyltä. Hän oli ehdottanut pitävänsä raamattua polvillaan
sormellansa siihen osottaen kuten hän oli eräässä kuvassa nähnyt
tohtori Valterin tekevän; mutta Falk oli saanut hänet siitä
luopumaan, koska se olisi ollut jälittelemistä. Sitten ajatteli hän
muita asentoja, joita hän, Abraham Jensen itse olisi keksinyt, mutta
ei löytänyt sopivia. Falkista oli sietämätöintä kuunnella hänen
henkivoimaista lörpötystänsä, Senlaisen piinan jälkeen kiiruhti hän
aina Saaran luo virkistyäksensä. Ei hän salannut Saaralta, että piti
hänen miestänsä ikävänä, mutta Saara vaan nauroi sille. Miehensä,
läsnäollessakin oli hän nyt vapaampi kuin ennen, vaikka hän
kärsivällisesti noudatti talon tapoja ja alentautui aviolliseen
suudelmaan ruoka-ateriain jälkeen.
Falk punastui.
— Oletteko luterilainen?
— En.
— Luulen, että jos ei mies ja vaimo syystä tai toisesta elä sovussa,
vaan katkeroittavat toisensa elämää, niin on parempi heidän erota
kuin jatkaa yhdyselämäänsä.
— Sen vaan sanon, että yksi sääntö tulee löytyä, muuten sortuu
kaikki pohjattomuuteen, — vastasi pappi.
— Oikein?
Falk itse jäi nyt hetkiseksi oheen. Hän olikin pari päivää ollut
kuvaamassa Saaran isää ja vanhusta, joka edelleenkin oli vuoteen
omana ja piirustellut samalla muutamia lehtipuita, joita oli sattunut
löytämään. Ei Saara häntä sanottavasti kaivannut. Olihan hänellä nyt
Jean Valjean, Marius ja Cosette. Kirjavana kuvastui maailma
edessään, vaiheineen, pahuuksineen, rikoksilleen ja himoineen, niin
että lukiessa sydäntä kouristutti ja hän huudahti lujaa, mutta myös
ihanana, viekoittelevana, rakkauksilleen ja itsensäkieltäymyksineen.
Kuinka jalo oli tuo katolinen piispa, joka runsaalla mitalla jakoi
rakkautta ja anteeksiantavaisuutta kaleriorjalle, vaikka tämä olikin
pettänyt häntä ja varastanutkin! — Niin, se oli toista se pappi!… Ja
hän oli katolinen! Hän oli aina katolisia pitänyt perkeleen lapsina, ei
yksistään uskossa erehtyneinä, vaan pahoina ja jumalattomina;
nehän olivat taistelleet Luterusta vastaan. Ja tämä piispa! Hänen
eteensä olisi hän tahtonut polvistua, laskea päänsä hänen
helmaansa anoen hänen siunaustansa. Ja hän oli katolilainen! Oli siis
hyviäkin katolilaisia, vaikka koulumestari oli sanonut, että niitä tuli
välttää kuin sielunvihollista. Koulumestari, — Saara hymyili ivallisesti
— mitä oli koulumestari, mitä koko hänen mitätöin kuulijakuntansa,
joihin hän itsekin kuului, tämän yhden ainoan rakkauden sankarin
rinnalla? Ja hän oli katolilainen.
— Myisi?
— No?
Kumminkin oli papin kuva se, jonka turvissa hän viipyi niin kauan.
Hän työskenteli hitaasti, sillä sen valmistuttua saisi hän lähteä
matkaan. Hän tekeytyy mahdollisimman miellyttäväksi, jopa oli
osallisena seurakunnan rakkausaterioillakin metsässä, missä
puhuttiin paljon, juotiin paljon kahvia, ja oli hyvin ikävää ja missä
hurskaat naiset utelijaina seurasivat papinrouvan pienintäkin liikettä
maalarin läsnäollessa. Falk huomasi kyllä, että heidän yhteiset
metsäkulkunsa olivat puheen alaisina. Siksi ei hän ollut Saaran
huomaavinaankaan, laski leikkiä eukkojen kanssa, niin että he
unohtivat tekopyhyytensä ja nauroivat makeasti. Hän oli oikein
hauska mies ja vaikka olikin maailman lapsi niin pitivät he hänestä
sittenkin. Saara käsitti myöskin juonen, eikä luonut silmäystäkään
Falkin seurueesen. Kaikki päättyi oivallisesti, akat hajaantuivat eri
suunnille, ja he jatkoivat hauskaa yhdyselämäänsä.
— No minkälainen se on?
— En.