The Ultimate Docker Container Book: Build, test, ship, and run containers with Docker and Kubernetes

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Build, ship, and run containers from scratch with Docker and Kubernetes be it on premise or in the cloud Key Features Master Docker container setup, operation, and debugging Use Docker compose for managing multi-service applications Navigate orchestrators like Kubernetes and Docker swarmkit Purchase of the print or Kindle book includes a free PDF eBook Book Description The Ultimate Docker Container Book, 3rd edition enables you to leverage Docker containers for streamlined software development. You’ll uncover Docker fundamentals and how containers improve software supply chain efficiency and enhance security. You’ll start by learning practical skills such as setting up Docker environments, handling stateful components, running and testing code within containers, and managing Docker images. You’ll also explore how to adapt legacy applications for containerization and understand distributed application architecture. Next, you’ll delve into Docker's networking model, software-defined networks for secure applications, and Docker compose for managing multi-service applications along with tools for log analysis and metrics. You’ll further deepen your understanding of popular orchestrators like Kubernetes and Docker swarmkit, exploring their key concepts, and deployment strategies for resilient applications. In the final sections, you’ll gain insights into deploying containerized applications on major cloud platforms, including Azure, AWS, and GCE and discover techniques for production monitoring and troubleshooting. By the end of this book, you’ll be well-equipped to manage and scale containerized applications effectively. What you will learn Understand the benefits of using containers Manage Docker containers effectively Create and manage Docker images Explore data volumes and environment variables Master distributed application architecture Deep dive into Docker networking Use Docker Compose for multi-service apps Deploy apps on major cloud platforms Who this book is for This book is for Linux professionals, system administrators, operations engineers, DevOps engineers, software architects, and developers looking to work with Docker and Kubernetes from scratch. A basic understanding of Docker containers is recommended, but no prior knowledge of Kubernetes is required. Familiarity with scripting tools such as Bash or PowerShell will be advantageous.

Author(s): Dr. Gabriel N. Schenker
Edition: 3
Publisher: Packt Publishing
Year: 2023

Language: English
Pages: 626

Cover
Title Page
Copyright and Credits
Contributors
Table of Contents
Preface
Part 1:Introduction
Chapter 1: What Are Containers and Why Should I Use Them?
What are containers?
Why are containers important?
What is the benefit of using containers for me or for my company?
The Moby project
Docker products
Docker Desktop
Docker Hub
Docker Enterprise Edition
Container architecture
Summary
Further reading
Questions
Answers
Chapter 2: Setting Up a Working Environment
Technical requirements
The Linux command shell
PowerShell for Windows
Installing and using a package manager
Installing Homebrew on macOS
Installing Chocolatey on Windows
Installing Git and cloning the code repository
Choosing and installing a code editor
Installing VS Code on macOS
Installing VS Code on Windows
Installing VS Code on Linux
Installing VS Code extensions
Installing Docker Desktop on macOS or Windows
Testing Docker Engine
Testing Docker Desktop
Installing Docker Toolbox
Enabling Kubernetes on Docker Desktop
Installing minikube
Installing minikube on Linux, macOS, and Windows
Testing minikube and kubectl
Working with a multi-node minikube cluster
Installing Kind
Testing Kind
Summary
Further reading
Questions
Answers
Part 2:Containerization Fundamentals
Chapter 3: Mastering Containers
Technical requirements
Running the first container
Starting, stopping, and removing containers
Running a random trivia question container
Listing containers
Stopping and starting containers
Removing containers
Inspecting containers
Exec into a running container
Attaching to a running container
Retrieving container logs
Logging drivers
Using a container-specific logging driver
Advanced topic – changing the default logging driver
The anatomy of containers
Architecture
Namespaces
Control groups
Union filesystem
Container plumbing
Summary
Further reading
Questions
Answers
Chapter 4: Creating and Managing Container Images
What are images?
The layered filesystem
The writable container layer
Copy-on-write
Graph drivers
Creating Docker images
Interactive image creation
Using Dockerfiles
Saving and loading images
Lift and shift – containerizing a legacy app
Analyzing external dependencies
Source code and build instructions
Configuration
Secrets
Authoring the Dockerfile
Why bother?
Sharing or shipping images
Tagging an image
Demystifying image namespaces
Explaining official images
Pushing images to a registry
Summary
Questions
Answers
Chapter 5: Data Volumes and Configuration
Technical requirements
Creating and mounting data volumes
Modifying the container layer
Creating volumes
Mounting a volume
Removing volumes
Accessing Docker volumes
Sharing data between containers
Using host volumes
Defining volumes in images
Configuring containers
Defining environment variables for containers
Using configuration files
Defining environment variables in container images
Environment variables at build time
Summary
Further reading
Questions
Answers
Chapter 6: Debugging Code Running in Containers
Technical requirements
Evolving and testing code running in a container
Mounting evolving code into the running container
Auto-restarting code upon changes
Auto-restarting for Node.js
Auto-restarting for Java and Spring Boot
Auto-restarting for Python
Auto-restarting for .NET
Line-by-line code debugging inside a container
Debugging a Node.js application
Debugging a .NET application
Instrumenting your code to produce meaningful logging information
Instrumenting a Python application
Instrumenting a .NET C# application
Using Jaeger to monitor and troubleshoot
Summary
Questions
Answers
Chapter 7: Testing Applications Running in Containers
Technical requirements
Benefits of testing applications in containers
Why do we test?
Manual versus automated testing
Why do we test in containers?
Different types of testing
Unit tests
Integration tests
Acceptance tests
Commonly used tools and technologies
Implementing a sample component
Implementing and running unit and integration tests
Implementing and running black box tests
Best practices for setting up a testing environment
Tips for debugging and troubleshooting issues
Challenges and considerations when testing applications running in containers
Case studies
Summary
Questions
Answers
Chapter 8: Increasing Productivity with Docker Tips and Tricks
Technical requirements
Keeping your Docker environment clean
Using a .dockerignore file
Executing simple admin tasks in a container
Running a Perl script
Running a Python script
Limiting the resource usage of a container
Avoiding running a container as root
Running Docker from within Docker
Optimizing your build process
Scanning for vulnerabilities and secrets
Using Snyk to scan a Docker image
Using docker scan to scan a Docker image for vulnerabilities
Running your development environment in a container
Summary
Questions
Answers
Part 3:Orchestration Fundamentals
Chapter 9: Learning about Distributed Application Architecture
What is a distributed application architecture?
Defining the terminology
Patterns and best practices
Loosely coupled components
Stateful versus stateless
Service discovery
Routing
Load balancing
Defensive programming
Redundancy
Health checks
Circuit breaker pattern
Running in production
Logging
Tracing
Monitoring
Application updates
Summary
Further reading
Questions
Answers
Chapter 10: Using Single-Host Networking
Technical requirements
Dissecting the container network model
Network firewalling
Working with the bridge network
The host and null networks
The host network
The null network
Running in an existing network namespace
Managing container ports
HTTP-level routing using a reverse proxy
Containerizing the monolith
Extracting the first microservice
Using Traefik to reroute traffic
Summary
Further reading
Questions
Answers
Chapter 11: Managing Containers with Docker Compose
Technical requirements
Demystifying declarative versus imperative orchestration of containers
Running a multi-service app
Building images with Docker Compose
Running an application with Docker Compose
Scaling a service
Building and pushing an application
Using Docker Compose overrides
Summary
Further reading
Questions
Answers
Chapter 12: Shipping Logs and Monitoring Containers
Technical requirements
Why is logging and monitoring important?
Shipping containers and Docker daemon logs
Shipping container logs
Shipping Docker daemon logs
Querying a centralized log
Step 1 – accessing Kibana
Step 2 – setting up an index pattern
Step 3 – querying the logs in Kibana
Step 4 – visualizing the logs
Collecting and scraping metrics
Step 1 – running cAdvisor in a Docker container
Step 2 – setting up and running Prometheus
Monitoring a containerized application
Step 1 – setting up Prometheus
Step 2 – instrumenting your application with Prometheus metrics
Step 3 – configuring Prometheus to scrape your application metrics
Step 4 – setting up Grafana for visualization
Step 5 – setting up alerting (optional)
Step 6 – monitoring your containerized application
Summary
Questions
Answers
Chapter 13: Introducing Container Orchestration
What are orchestrators and why do we need them?
The tasks of an orchestrator
Reconciling the desired state
Replicated and global services
Service discovery
Routing
Load balancing
Scaling
Self-healing
Data persistence and storage management
Zero downtime deployments
Affinity and location awareness
Security
Introspection
Overview of popular orchestrators
Kubernetes
Docker Swarm
Apache Mesos and Marathon
Amazon ECS
AWS EKS
Microsoft ACS and AKS
Summary
Further reading
Questions
Answers
Chapter 14: Introducing Docker Swarm
The Docker Swarm architecture
Swarm nodes
Stacks, services, and tasks
Services
Tasks
Stacks
Multi-host networking
Creating a Docker Swarm
Creating a local single-node swarm
Using PWD to generate a Swarm
Creating a Docker Swarm in the cloud
Deploying a first application
Creating a service
Inspecting the service and its tasks
Testing the load balancing
Logs of a service
Reconciling the desired state
Deleting a service or a stack
Deploying a multi-service stack
Removing the swarm in AWS
Summary
Questions
Answers
Chapter 15: Deploying and Running a Distributed Application on Docker Swarm
The swarm routing mesh
Zero-downtime deployment
Popular deployment strategies
Rolling updates
Health checks
Rolling back
Blue-green deployments
Canary releases
Storing configuration data in the swarm
Protecting sensitive data with Docker secrets
Creating secrets
Using a secret
Simulating secrets in a development environment
Secrets and legacy applications
Updating secrets
Summary
Questions
Answers
Part 4:Docker, Kubernetes, and the Cloud
Chapter 16: Introducing Kubernetes
Technical requirements
Understanding Kubernetes architecture
Kubernetes master nodes
Cluster nodes
Introduction to Play with Kubernetes
Kubernetes support in Docker Desktop
Introduction to pods
Comparing Docker container and Kubernetes pod networking
Sharing the network namespace
Pod life cycle
Pod specifications
Pods and volumes
Kubernetes ReplicaSets
ReplicaSet specification
Self-healing
Kubernetes Deployments
Kubernetes Services
Context-based routing
Comparing SwarmKit with Kubernetes
Summary
Further reading
Questions
Answers
Chapter 17: Deploying, Updating, and Securing an Application with Kubernetes
Technical requirements
Deploying our first application
Deploying the web component
Deploying the database
Defining liveness and readiness
Kubernetes liveness probes
Kubernetes readiness probes
Kubernetes startup probes
Zero-downtime deployments
Rolling updates
Blue-green deployment
Kubernetes secrets
Manually defining secrets
Creating secrets with kubectl
Using secrets in a pod
Secret values in environment variables
Summary
Further reading
Questions
Answers
Chapter 18: Running a Containerized Application in the Cloud
Technical requirements
Why choose a hosted Kubernetes service?
Running a simple containerized application on Amazon EKS
Exploring Microsoft’s AKS
Preparing the Azure CLI
Creating a container registry on Azure
Pushing our images to ACR
Creating a Kubernetes cluster
Deploying our application to the Kubernetes cluster
Understanding GKE
Summary
Questions
Answers
Chapter 19: Monitoring and Troubleshooting an Application Running in Production
Technical requirements
Monitoring an individual service
Using OpenTracing for distributed tracing
A Java example
Instrumenting a Node.js-based service
Instrumenting a .NET service
Leveraging Prometheus and Grafana to monitor a distributed application
Architecture
Deploying Prometheus to Kubernetes
Deploying our application services to Kubernetes
Deploying Grafana to Kubernetes
Defining alerts based on key metrics
Metrics
Alerts
Defining alerts
Runbooks
Troubleshooting a service running in production
The netshoot container
Summary
Questions
Answers
Index
Other Books You May Enjoy