The Ultimate Docker Container Book - Third Edition

Book description

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.

Table of contents

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

Product information

  • Title: The Ultimate Docker Container Book - Third Edition
  • Author(s): Dr. Gabriel N. Schenker
  • Release date: August 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781804613986