Learn Docker - Fundamentals of Docker 19.x - Second Edition

Book description

Explore the core functionality of containerizing your applications and making them production-ready

Key Features

  • Grasp basic to advanced Docker concepts with this comprehensive guide
  • Get acquainted with Docker containers, Docker images, orchestrators, cloud integration, and networking
  • Learn to simplify dependencies and deploy and test containers in production

Book Description

Containers enable you to package an application with all the components it needs, such as libraries and other dependencies, and ship it as one package. Docker containers have revolutionized the software supply chain in both small and large enterprises.

Starting with an introduction to Docker fundamentals and setting up an environment to work with it, you'll delve into concepts such as Docker containers, Docker images, and Docker Compose. As you progress, the book will help you explore deployment, orchestration, networking, and security. Finally, you'll get to grips with Docker functionalities on public clouds such as Amazon Web Services (AWS), Azure, and Google Cloud Platform (GCP), and learn about Docker Enterprise Edition features. Additionally, you'll also discover the benefits of increased security with the use of containers.

By the end of this Docker book, you'll be able to build, ship, and run a containerized, highly distributed application on Docker Swarm or Kubernetes, running on-premises or in the cloud.

What you will learn

  • Containerize your traditional or microservice-based applications
  • Develop, modify, debug, and test an application running inside a container
  • Share or ship your application as an immutable container image
  • Build a Docker Swarm and a Kubernetes cluster in the cloud
  • Run a highly distributed application using Docker Swarm or Kubernetes
  • Update or rollback a distributed application with zero downtime
  • Secure your applications with encapsulation, networks, and secrets
  • Troubleshoot a containerized, highly distributed application in the cloud

Who this book is for

This book is for system administrators, operations engineers, DevOps engineers, and developers or stakeholders who are interested in getting started with Docker from scratch. No prior experience with Docker containers is required.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Learn Docker – Fundamentals of Docker 19.x Second Edition
  3. About Packt
    1. Why subscribe?
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Section 1: Motivation and Getting Started
  7. What Are Containers and Why Should I Use Them?
    1. What are containers?
    2. Why are containers important?
    3. What's the benefit for me or for my company?
    4. The Moby project
    5. Docker products
      1. Docker CE
      2. Docker EE
    6. Container architecture
    7. Summary
    8. Questions
    9. Further reading
  8. Setting Up a Working Environment
    1. Technical requirements
    2. The Linux command shell
    3. PowerShell for Windows
    4. Using a package manager
      1. Installing Homebrew on macOS
      2. Installing Chocolatey on Windows
    5. Installing Git
    6. Choosing 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 for Desktop
      1. Installing Docker for Desktop on macOS
      2. Installing Docker for Desktop on Windows
      3. Installing Docker CE on Linux
    8. Installing Docker Toolbox
      1. Installing Docker Toolbox on macOS
      2. Installing Docker Toolbox on Windows
      3. Setting up Docker Toolbox
    9. Installing Minikube
      1. Installing Minikube on macOS and Windows
      2. Testing Minikube and kubectl
    10. Summary
    11. Questions
    12. Further reading
  9. Section 2: Containerization, from Beginner to Black Belt
  10. Mastering Containers
    1. Technical requirements
    2. Running the first container
    3. Starting, stopping, and removing containers
      1. Running a random trivia question container
      2. Listing containers
      3. Stopping and starting containers
      4. Removing containers
    4. Inspecting containers
    5. Exec into a running container
    6. Attaching to a running container
    7. Retrieving container logs
      1. Logging drivers
      2. Using a container-specific logging driver
      3. Advanced topic – changing the default logging driver
    8. Anatomy of containers
      1. Architecture
      2. Namespaces
      3. Control groups (cgroups)
      4. Union filesystem (Unionfs)
      5. Container plumbing
        1. runC
        2. Containerd
    9. Summary
    10. Questions
    11. Further reading
  11. 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 images
      1. Interactive image creation
      2. Using Dockerfiles
        1. The FROM keyword
        2. The RUN keyword
        3. The COPY and ADD keywords
        4. The WORKDIR keyword
        5. The CMD and ENTRYPOINT keywords
        6. A complex Dockerfile
        7. Building an image
        8. Multi-step builds
        9. Dockerfile best practices
      3. Saving and loading images
    3. Lift and shift: Containerizing a legacy app
      1. Analysis of external dependencies
      2. Source code and build instructions
      3. Configuration
      4. Secrets
      5. Authoring the Dockerfile
        1. The base image
        2. Assembling the sources
        3. Building the application
        4. Defining the start command
      6. Why bother?
    4. Sharing or shipping images
      1. Tagging an image
      2. Image namespaces
      3. Official images
      4. Pushing images to a registry
    5. Summary
    6. Questions
    7. Further reading
  12. 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 volumes created with Docker for Desktop
    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. Questions
    9. Further reading
  13. 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 Python
      3. 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. Further reading
  14. Using Docker to Supercharge Automation
    1. Technical requirements
    2. Executing simple admin tasks in a container
    3. Using test containers
      1. Integration tests for a Node.js application
      2. The Testcontainers project
    4. Using Docker to power a CI/CD pipeline
    5. Summary
    6. Questions
    7. Further reading
  15. Advanced Docker Usage Scenarios
    1. Technical requirements
    2. All of the tips and tricks of a Docker pro
      1. Keeping your Docker environment clean
      2. Running Docker in Docker
      3. Formatting the output of common Docker commands
      4. Filtering the output of common Docker commands
      5. Optimizing your build process
      6. Limiting resources consumed by a container
      7. Read-only filesystem
      8. Avoid running a containerized app as root 
    3. Running your Terminal in a remote container and accessing it via HTTPS
    4. Running your development environment inside a container
    5. Running your code editor in a remote container and accessing it via HTTPS
    6. Summary
    7. Questions
    8. Further reading
  16. Section 3: Orchestration Fundamentals and Docker Swarm
  17. Distributed Application Architecture
    1. Understanding the 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
        1. Retries
        2. Logging
        3. Error handling
      7. Redundancy
      8. Health checks
      9. Circuit breaker pattern
    3. Running in production
      1. Logging
      2. Tracing
      3. Monitoring
      4. Application updates
        1. Rolling updates
        2. Blue-green deployments
        3. Canary releases
        4. Irreversible data changes
        5. Rollback
    4. Summary
    5. Questions
    6. Further reading
  18. 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 network
      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. Questions
    11. Further reading
  19. Docker Compose
    1. Technical requirements
    2. Demystifying declarative versus imperative
    3. Running a multi-service app
      1. Building images with Docker Compose
      2. Running an application with Docker Compose
    4. Scaling a service
    5. Building and pushing an application
    6. Using Docker Compose overrides
    7. Summary
    8. Questions
    9. Further reading
  20. Orchestrators
    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. Zero downtime deployments
      9. Affinity and location awareness
      10. Security
        1. Secure communication and cryptographic node identity
        2. Secure networks and network policies
        3. Role-based access control (RBAC)
        4. Secrets
        5. Content trust
        6. Reverse uptime
      11. Introspection
    3. Overview of popular orchestrators
      1. Kubernetes
      2. Docker Swarm
      3. Apache Mesos and Marathon
      4. Amazon ECS
      5. Microsoft ACS 
    4. Summary
    5. Questions
    6. Further reading
  21. Introduction to Docker Swarm
    1. The Docker Swarm architecture
    2. Swarm nodes
      1. Swarm managers
      2. Swarm workers
    3. Stacks, services, and tasks
      1. Services
      2. Task
      3. Stack
    4. Multi-host networking
    5. Creating a Docker Swarm
      1. Creating a local single node swarm
      2. Creating a local Swarm in VirtualBox or Hyper-V
      3. Using Play with Docker to generate a Swarm
      4. Creating a Docker Swarm in the cloud
    6. Deploying a first application
      1. Creating a service
      2. Inspecting the service and its tasks
      3. Logs of a service
      4. Reconciling the desired state
      5. Deleting a service or a stack
      6. Deploying a multi-service stack
    7. The swarm routing mesh
    8. Summary
    9. Questions
    10. Further reading
  22. Zero-Downtime Deployments and Secrets
    1. Technical requirements
    2. Zero-downtime deployment
      1. Popular deployment strategies
      2. Rolling updates
      3. Health checks
      4. Rollback
      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. Further reading
  23. Section 4: Docker, Kubernetes, and the Cloud
  24. Introduction to Kubernetes
    1. Technical requirements
    2. Kubernetes architecture
    3. Kubernetes master nodes
    4. Cluster nodes
    5. Introduction to Minikube
    6. Kubernetes support in Docker for 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 ReplicaSet
      1. ReplicaSet specification
      2. Self-healing
    9. Kubernetes deployment
    10. Kubernetes service
    11. Context-based routing
    12. Comparing SwarmKit with Kubernetes
    13. Summary
    14. Questions
    15. Further reading
  25. Deploying, Updating, and Securing an Application with Kubernetes
    1. Technical requirements
    2. Deploying a first application
      1. Deploying the web component
      2. Deploying the database
      3. Streamlining the deployment
    3. Defining liveness and readiness
      1. Kubernetes liveness probe
      2. Kubernetes readiness probe
      3. Kubernetes startup probe
    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. Questions
    8. Further reading
  26. Monitoring and Troubleshooting an App Running in Production
    1. Technical requirements
    2. Monitoring an individual service
      1. Instrumenting a Node.js-based service
      2. Instrumenting a .NET Core-based service
    3. Using Prometheus to monitor a distributed application
      1. Architecture
      2. Deploying Prometheus to Kubernetes
      3. Deploying our application services to Kubernetes
      4. Deploying Grafana to Kubernetes
    4. Troubleshooting a service running in production
      1. The netshoot container
    5. Summary
    6. Questions
    7. Further reading
  27. Running a Containerized App in the Cloud
    1. Technical requirements
    2. Deploying and using Docker EE on AWS
      1. Provisioning the infrastructure
      2. Installing Docker
      3. Installing Docker UCP
      4. Using remote admin for the UCP cluster
      5. Deploying to Docker Swarm
      6. Deploying to Kubernetes
    3. Exploring Microsoft's Azure Kubernetes Service (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
    4. Understanding GKE
    5. Summary
    6. Questions
    7. Further reading
  28. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7 
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
    13. Chapter 13
    14. Chapter 14
    15. Chapter 15
    16. Chapter 16
    17. Chapter 17
    18. Chapter 18
  29. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Learn Docker - Fundamentals of Docker 19.x - Second Edition
  • Author(s): Gabriel N. Schenker
  • Release date: March 2020
  • Publisher(s): Packt Publishing
  • ISBN: 9781838827472