ebook img

Learn Docker - Fundamentals of Docker 19.x PDF

574 Pages·2020·26.011 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Learn Docker - Fundamentals of Docker 19.x

Learn Docker – Fundamentals of Docker 19.x Second Edition Build, test, ship, and run containers with Docker and Kubernetes Gabriel N. Schenker BIRMINGHAM - MUMBAI Learn Docker – Fundamentals of Docker 19.x Second Edition Copyright © 2020 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Commissioning Editor: Vijin Boricha Acquisition Editor: Shrilekha Inani Content Development Editor: Ronn Kurien Senior Editor: Richard Brookes-Bland Technical Editor: Sarvesh Jaywant Copy Editor: Safis Editing Project Coordinator: Neil Dmello Proofreader: Safis Editing Indexer: Tejal Daruwale Soni Production Designer: Deepika Naik First published: April 2018 Second edition: March 2020 Production reference: 1130320 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-83882-747-2 www.packt.com Packt.com Subscribe to our online digital library for full access to over 7,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website. Why subscribe? Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free eBook or video every month Fully searchable for easy access to vital information Copy and paste, print, and bookmark content Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. Contributors About the author Gabriel N. Schenker has more than 25 years of experience as an independent consultant, architect, leader, trainer, mentor, and developer. Currently, Gabriel works as Lead Solution Architect at Techgroup Switzerland. Prior to that, Gabriel worked as Lead Curriculum Developer at Docker and at Confluent. Gabriel has a Ph.D. in Physics, and he is a Docker Captain, a Certified Docker Associate, a Certified Kafka Developer and Operator, and an ASP Insider. When not working, Gabriel enjoys time with his wonderful wife Veronicah and his children. I want to give special thanks to my editors, Ronn Kurien and Suzanne Coutinho, who patiently helped me to get this book done and get it done right. About the reviewer Francisco Javier Ramírez Urea is a technology enthusiast and professional, Docker Captain, casual developer, open source advocate, a certified trainer and solutions architect at HoplaSoftware, and a technical book writer and reviewer. He is also a Kubernetes Certified Administrator, a Docker Certified Associate, a Docker Certified Instructor, and a Docker MTA program Consultant, as well as a Docker/Kubernetes and NGINX expert and a DevOps/CI-CD solutions integrator. He currently works as a solutions architect focused on containers and microservices technologies. He is passionate to teach his students everything he know. Continuous learning is the main motivation of his career. Packt is searching for authors like you If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea. Table of Contents Preface 1 Section 1: Section 1: Motivation and Getting Started Chapter 1: What Are Containers and Why Should I Use Them? 10 What are containers? 11 Why are containers important? 14 What's the benefit for me or for my company? 16 The Moby project 16 Docker products 17 Docker CE 17 Docker EE 18 Container architecture 18 Summary 19 Questions 20 Further reading 21 Chapter 2: Setting Up a Working Environment 22 Technical requirements 23 The Linux command shell 23 PowerShell for Windows 24 Using a package manager 24 Installing Homebrew on macOS 24 Installing Chocolatey on Windows 25 Installing Git 26 Choosing a code editor 27 Installing VS Code on macOS 27 Installing VS Code on Windows 28 Installing VS Code on Linux 28 Installing VS Code extensions 29 Installing Docker for Desktop 29 Installing Docker for Desktop on macOS 31 Installing Docker for Desktop on Windows 33 Installing Docker CE on Linux 34 Installing Docker Toolbox 34 Installing Docker Toolbox on macOS 35 Installing Docker Toolbox on Windows 36 Setting up Docker Toolbox 37 Installing Minikube 41 Table of Contents Installing Minikube on macOS and Windows 41 Testing Minikube and kubectl 41 Summary 43 Questions 43 Further reading 44 Section 2: Section 2: Containerization, from Beginner to Black Belt Chapter 3: Mastering Containers 46 Technical requirements 47 Running the first container 47 Starting, stopping, and removing containers 49 Running a random trivia question container 51 Listing containers 53 Stopping and starting containers 55 Removing containers 57 Inspecting containers 57 Exec into a running container 59 Attaching to a running container 60 Retrieving container logs 62 Logging drivers 63 Using a container-specific logging driver 64 Advanced topic – changing the default logging driver 65 Anatomy of containers 66 Architecture 67 Namespaces 67 Control groups (cgroups) 69 Union filesystem (Unionfs) 70 Container plumbing 70 runC 70 Containerd 71 Summary 71 Questions 71 Further reading 71 Chapter 4: Creating and Managing Container Images 73 What are images? 74 The layered filesystem 74 The writable container layer 76 Copy-on-write 77 Graph drivers 78 Creating images 78 Interactive image creation 78 Using Dockerfiles 82 [ ii ] Table of Contents The FROM keyword 83 The RUN keyword 84 The COPY and ADD keywords 85 The WORKDIR keyword 86 The CMD and ENTRYPOINT keywords 87 A complex Dockerfile 89 Building an image 90 Multi-step builds 94 Dockerfile best practices 96 Saving and loading images 98 Lift and shift: Containerizing a legacy app 99 Analysis of external dependencies 100 Source code and build instructions 100 Configuration 101 Secrets 101 Authoring the Dockerfile 102 The base image 102 Assembling the sources 102 Building the application 103 Defining the start command 103 Why bother? 104 Sharing or shipping images 105 Tagging an image 105 Image namespaces 105 Official images 108 Pushing images to a registry 108 Summary 109 Questions 109 Further reading 110 Chapter 5: Data Volumes and Configuration 111 Technical requirements 112 Creating and mounting data volumes 112 Modifying the container layer 112 Creating volumes 113 Mounting a volume 116 Removing volumes 118 Accessing volumes created with Docker for Desktop 119 Sharing data between containers 122 Using host volumes 124 Defining volumes in images 126 Configuring containers 129 Defining environment variables for containers 130 Using configuration files 131 Defining environment variables in container images 133 Environment variables at build time 134 [ iii ] Table of Contents Summary 135 Questions 135 Further reading 136 Chapter 6: Debugging Code Running in Containers 137 Technical requirements 138 Evolving and testing code running in a container 138 Mounting evolving code into the running container 142 Auto restarting code upon changes 145 Auto-restarting for Node.js 145 Auto-restarting for Python 147 Auto-restarting for .NET 150 Line-by-line code debugging inside a container 155 Debugging a Node.js application 156 Debugging a .NET application 161 Instrumenting your code to produce meaningful logging information 165 Instrumenting a Python application 166 Instrumenting a .NET C# application 168 Using Jaeger to monitor and troubleshoot 172 Summary 177 Questions 177 Further reading 178 Chapter 7: Using Docker to Supercharge Automation 179 Technical requirements 180 Executing simple admin tasks in a container 180 Using test containers 183 Integration tests for a Node.js application 186 The Testcontainers project 196 Using Docker to power a CI/CD pipeline 203 Summary 217 Questions 218 Further reading 218 Chapter 8: Advanced Docker Usage Scenarios 219 Technical requirements 220 All of the tips and tricks of a Docker pro 220 Keeping your Docker environment clean 220 Running Docker in Docker 221 Formatting the output of common Docker commands 224 Filtering the output of common Docker commands 225 Optimizing your build process 225 Limiting resources consumed by a container 227 Read-only filesystem 228 [ iv ]

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.