Immediate Download Using Docker Developing and Deploying Software With Containers 1st Edition Adrian Mouat Ebooks 2024
Immediate Download Using Docker Developing and Deploying Software With Containers 1st Edition Adrian Mouat Ebooks 2024
com
https://textbookfull.com/product/using-docker-
developing-and-deploying-software-with-
containers-1st-edition-adrian-mouat/
https://textbookfull.com/product/docker-containers-build-and-deploy-
with-kubernetes-flannel-cockpit-and-atomic-first-printing-edition-
henry/
textbookfull.com
https://textbookfull.com/product/crispr-people-the-science-and-ethics-
of-editing-humans-1st-edition-henry-t-greely/
textbookfull.com
Foundations for Lifelong Learning John Piper
https://textbookfull.com/product/foundations-for-lifelong-learning-
john-piper/
textbookfull.com
https://textbookfull.com/product/site-reliability-engineering-how-
google-runs-production-systems-1st-edition-betsy-beyer/
textbookfull.com
https://textbookfull.com/product/controlled-radical-polymerization-at-
and-from-solid-surfaces-1st-edition-philipp-vana-eds/
textbookfull.com
https://textbookfull.com/product/oxford-handbook-of-rheumatology-
gavin-clunie/
textbookfull.com
https://textbookfull.com/product/ocular-fluid-dynamics-anatomy-
physiology-imaging-techniques-and-mathematical-modeling-giovanna-
guidoboni/
textbookfull.com
Using
Docker
DEVELOPING AND DEPLOYING SOFTWARE WITH CONTAINERS
Adrian Mouat
www.it-ebooks.info
www.it-ebooks.info
Using Docker
Adrian Mouat
Boston
www.it-ebooks.info
Using Docker
by Adrian Mouat
Copyright © 2016 Adrian Mouat. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or [email protected].
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Using Docker, the cover image, and
related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the author disclaim all responsibility
for errors or omissions, including without limitation responsibility for damages resulting from the use of
or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.
978-1-491-91576-9
[LSI]
www.it-ebooks.info
To those who try, whether they fail or succeed.
www.it-ebooks.info
www.it-ebooks.info
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
2. Installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Installing Docker on Linux 13
Run SELinux in Permissive Mode 14
Running Without sudo 15
Installing Docker on Mac OS or Windows 15
A Quick Check 17
3. First Steps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Running Your First Image 19
The Basic Commands 20
Building Images from Dockerfiles 24
Working with Registries 27
Private Repositories 29
Using the Redis Official Image 30
Conclusion 33
www.it-ebooks.info
4. Docker Fundamentals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
The Docker Architecture 35
Underlying Technologies 36
Surrounding Technologies 37
Docker Hosting 39
How Images Get Built 39
The Build Context 39
Image Layers 41
Caching 43
Base Images 44
Dockerfile Instructions 46
Connecting Containers to the World 49
Linking Containers 49
Managing Data with Volumes and Data Containers 51
Sharing Data 53
Data Containers 54
Common Docker Commands 55
The run Command 56
Managing Containers 59
Docker Info 62
Container Info 62
Dealing with Images 63
Using the Registry 66
Conclusion 67
vi | Table of Contents
www.it-ebooks.info
7. Image Distribution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Image and Repository Naming 99
The Docker Hub 100
Automated Builds 102
Private Distribution 104
Running Your Own Registry 104
Commerical Registries 111
Reducing Image Size 111
Image Provenance 113
Conclusion 114
www.it-ebooks.info
Sharing Secrets 167
Saving Secrets in the Image 167
Passing Secrets in Environment Variables 168
Passing Secrets in Volumes 168
Using a Key-Value Store 169
Networking 170
Production Registry 170
Continuous Deployment/Delivery 171
Conclusion 171
www.it-ebooks.info
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Networking Solutions 230
Overlay 231
Weave 233
Flannel 237
Project Calico 242
Conclusion 246
Table of Contents | ix
www.it-ebooks.info
Linux Security Modules 318
SELinux 319
AppArmor 322
Auditing 322
Incident Response 323
Future Features 324
Conclusion 324
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
x | Table of Contents
www.it-ebooks.info
Preface
Containers are a lightweight and portable store for an application and its dependencies.
Written down by itself, this sounds dry and boring. But the process improvements
made possible by containers are anything but; used correctly, containers can be game-
changing. So persuasive is the lure of the architectures and workflows made possible
by containers that it feels like every major IT company has gone in a year from never
having heard of Docker or containers to actively investigating and using them.
The rise of Docker has been astonishing. I don’t remember any technology that has
had such a fast and profound effect on the IT industry. This book is my attempt to
help you understand why containers are so important, what you stand to gain from
adopting containerization and, most importantly, how to go about it.
xi
www.it-ebooks.info
make the most of the containerization movement, I will have achieved more than I
have in years of developing software.
I truly hope that you enjoy reading this book and that it helps you on the path to
using Docker in your organization.
• Part I starts by explaining what containers are and why you should be interested
in them, before going into a tutorial chapter showing the basics of Docker. It ends
with a large chapter explaining the fundamental concepts and technology in
Docker, including an overview of the various Docker commands.
• Part II explains how to use Docker in a software-development lifecycle. It starts
by showing how to set up a development environment, before building a simple
web application that is used as an ongoing example through the rest of Part II.
The chapter covers development, testing, and integration, as well as how to
deploy containers and how to effectively monitor and log a production system.
• Part III goes into advanced details and the tools and techniques needed to run
multihost clusters of Docker containers safely and reliably. If you are already
using Docker and need to understand how to scale up or solve networking and
security issues, this is for you.
xii | Preface
www.it-ebooks.info
This icon signifies a tip, suggestion, or general note.
Technology professionals, software developers, web designers, and business and crea‐
tive professionals use Safari Books Online as their primary resource for research,
problem solving, learning, and certification training.
Preface | xiii
www.it-ebooks.info
Safari Books Online offers a range of plans and pricing for enterprise, government,
education, and individuals.
Members have access to thousands of books, training videos, and prepublication
manuscripts in one fully searchable database from publishers like O’Reilly Media,
Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que,
Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kauf‐
mann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders,
McGraw-Hill, Jones & Bartlett, Course Technology, and hundreds more. For more
information about Safari Books Online, please visit us online.
How to Contact Us
Please address comments and questions concerning this book to the publisher:
We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at http://bit.ly/using-docker.
To comment or ask technical questions about this book, send email to bookques‐
[email protected].
For more information about our books, courses, conferences, and news, see our web‐
site at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
Acknowledgments
I am immensely grateful for all the help, advice, and criticism I received during the
writing of this book. If I missed your name in the following list, please accept my
apologies; your contribution was appreciated whether I acted on it or not.
For their generous feedback, I would like to thank Ally Hume, Tom Sugden, Lukasz
Guminski, Tilaye Alemu, Sebastien Goasguen, Maxim Belooussov, Michael Boelen,
xiv | Preface
www.it-ebooks.info
Ksenia Burlachenko, Carlos Sanchez, Daniel Bryant, Christoffer Holmstedt, Mike
Rathbun, Fabrizio Soppelsa, Yung-Jin Hu, Jouni Miikki, and Dale Bewley.
For technical conversations and input on specific technologies in the book, I would
like to thank Andrew Kennedy, Peter White, Alex Pollitt, Fintan Ryan, Shaun Cramp‐
ton, Spike Curtis, Alexis Richardson, Ilya Dmitrichenko, Casey Bisson, Thijs
Schnitger, Sheng Liang, Timo Derstappen, Puja Abbassi, Alexander Larsson, and Kel‐
sey Hightower. For allowing me to reuse monsterid.js, I would like to thank Kevin
Gaudin.
For all their help, I would like to thank the O’Reilly staff, in particular my editor Brian
Anderson and Meghan Blanchette, for starting the whole process.
Diogo Mónica and Mark Coleman—thanks to both of you for answering my last-
minute plea for help.
A particular shout-out has to go to two companies: Container Solutions and Cloud‐
Soft. Jamie Dobson and Container Solutions kept me busy blogging and speaking at
events, and put me in contact with several people who had an impact on this book.
CloudSoft graciously allowed me to use their office during the writing of this book
and hosted the Edinburgh Docker meetup, both of which were very important to me.
For putting up with my obsession and moaning over the book, I would like to thank
all my friends and family; you know who you are (and are unlikely to read this any‐
way).
Finally, I would like to thank the BBC 6 Music DJs who provided the soundtrack to
this book, including Lauren Laverne, Radcliffe and Maconie, Shaun Keaveny, and
Iggy Pop.
Preface | xv
www.it-ebooks.info
www.it-ebooks.info
PART I
Background and Basics
In the first part of this book, we’ll start by taking look at what containers are and why
they are becoming so popular. This is followed by an introduction to Docker and the
key concepts you need to understand to make the most of containers.
www.it-ebooks.info
www.it-ebooks.info
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
CHAPTER 1
The What and Why of Containers
Containers are fundamentally changing the way we develop, distribute, and run soft‐
ware. Developers can build software locally, knowing that it will run identically
regardless of host environment—be it a rack in the IT department, a user’s laptop, or
a cluster in the cloud. Operations engineers can concentrate on networking, resour‐
ces, and uptime and spend less time configuring environments and battling system
dependencies. The use and uptake of containers is increasing at a phenomenal rate
across the industry, from the smallest start ups to large-scale enterprises. Developers
and operations engineers should expect to regularly use containers in some fashion
within the next few years.
Containers are an encapsulation of an application with its dependencies. At first
glance, they appear to be just a lightweight form of virtual machines (VMs)—like a
VM, a container holds an isolated instance of an operating system (OS), which we
can use to run applications.
However, containers have several advantages that enable use cases that are difficult or
impossible with traditional VMs:
• Containers share resources with the host OS, which makes them an order of
magnitude more efficient. Containers can be started and stopped in a fraction of
a second. Applications running in containers incur little to no overhead com‐
pared to applications running natively on the host OS.
• The portability of containers has the potential to eliminate a whole class of bugs
caused by subtle changes in the running environment—it could even put an end
to the age-old developer refrain of “but it works on my machine!”
• The lightweight nature of containers means developers can run dozens of con‐
tainers at the same time, making it possible to emulate a production-ready dis‐
www.it-ebooks.info
tributed system. Operations engineers can run many more containers on a single
host machine than using VMs alone.
• Containers also have advantages for end users and developers outside of deploy‐
ing to the cloud. Users can download and run complex applications without
needing to spend hours on configuration and installation issues or worrying
about the changes required to their system. In turn, the developers of such appli‐
cations can avoid worrying about differences in user environments and the avail‐
ability of dependencies.
More importantly, the fundamental goals of VMs and containers are different—the
purpose of a VM is to fully emulate a foreign environment, while the purpose of a
container is to make applications portable and self-contained.
1 The diagram depicts a type 2 hypervisor, such as Virtualbox or VMWare Workstation, which runs on top of a
host OS. Type 1 hypervisors, such as Xen, are also available where the hypervisor runs directly on top of the
bare metal.
2 The kernel is the core component in an OS and is responsible for providing applications with essential system
functions related to memory, CPU, and device access. A full OS consists of the kernel plus various system
programs, such as init systems, compilers, and window managers.
www.it-ebooks.info
find hybrid systems with containers running inside VMs in order to take advantage
of both technologies.
www.it-ebooks.info
Docker and Containers
Containers are an old concept. For decades, UNIX systems have had the chroot com‐
mand that provides a simple form of filesystem isolation. Since 1998, FreeBSD has
had the jail utility, which extended chroot sandboxing to processes. Solaris Zones
offered a comparatively complete containerization technology around 2001 but was
limited to the Solaris OS. Also in 2001, Parrallels Inc, (then SWsoft) released the
commercial Virtuozzo container technology for Linux and later open sourced the
core technology as OpenVZ in 2005.3 Then Google started the development of
CGroups for the Linux kernel and began moving its infrastructure to containers. The
Linux Containers (LXC) project started in 2008 and brought together CGroups, ker‐
nel namespaces, and chroot technology (among others) to provide a complete con‐
tainerization solution. Finally, in 2013, Docker brought the final pieces to the
containerization puzzle, and the technology began to enter the mainstream.
Docker took the existing Linux container technology and wrapped and extended it in
various ways—primarily through portable images and a user-friendly interface—to
create a complete solution for the creation and distribution of containers. The Docker
platform has two distinct components: the Docker Engine, which is responsible for
creating and running containers; and the Docker Hub, a cloud service for distributing
containers.
The Docker Engine provides a fast and convenient interface for running containers.
Before this, running a container using a technology such as LXC required significant
specialist knowledge and manual work. The Docker Hub provides an enormous
number of public container images for download, allowing users to quickly get
started and avoid duplicating work already done by others. Further tooling developed
by Docker includes Swarm, a clustering manager; Kitematic, a GUI for working with
containers; and Machine, a command-line utility for provisioning Docker hosts.
By open sourcing the Docker Engine, Docker was able to grow a large community
around Docker and take advantage of public help with bug fixes and enhancements.
The rapid rise of Docker meant that it effectively became a de facto standard, which
led to industry pressure to move to develop independent formal standards for the
container runtime and format. In 2015, this culminated in the establishment of the
Open Container Initiative, a “governance structure” sponsored by Docker, Microsoft,
CoreOS, and many other important organizations, whose mission is to develop such
a standard. Docker’s container format and runtime forms the basis of the effort.
The uptake of containers has largely been driven by developers, who for the first time
were given the tools to use containers effectively. The fast start-up time of Docker
3 OpenVZ never achieved mass adoption, possibly because of the requirement to run a patched kernel.
www.it-ebooks.info
containers is essential to developers who crave quick and iterative development cycles
where they can promptly see the results of code changes. The portability and isolation
guarantees of containers ease collaboration with other developers and operations;
developers can be sure their code will work across environments, and operations can
focus on hosting and orchestrating containers rather than worrying about the code
running inside them.
The changes brought about by Docker are significantly changing the way we develop
software. Without Docker, containers would have remained in the shadows of IT for
a long time to come.
4 This originally stood for Linux, Apache, MySQL, and PHP—common components in a web application.
www.it-ebooks.info
Random documents with unrelated
content Scribd suggests to you:
this simple, Gospel way, wait the Lord’s leisure, and He will comfort
your heart.
“I hope you take care to have little or nothing else mentioned to
you but His praises and promises. Your tongue and ears are going to
be silent in the grave. Now, or never, you must use them to hear and
speak good of His name. Comfort your weeping friends. Reprove the
backsliders. Encourage seekers. Remember the praying, believing,
preaching, though dying thief. Be not afraid to drop a word for Him
who opens a fountain of blood for you. Suffer, live, die at His feet;
and you will soon revive, sing, and reign in His bosom for evermore.
Farewell, in the Conqueror of Death and Prince of Life.
“J. Fletcher.”[164]