O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learning Docker - Second Edition

Book Description

Docker lets you create, deploy, and manage your applications anywhere at anytime – flexibility is key so you can deploy stable, secure, and scalable app containers across a wide variety of platforms and delve into microservices architecture

About This Book

  • This up-to-date edition shows how to leverage Docker’s features to deploy your existing applications
  • Learn how to package your applications with Docker and build, ship, and scale your containers
  • Explore real-world examples of securing and managing Docker containers

Who This Book Is For

This book is ideal for developers, operations managers, and IT professionals who would like to learn about Docker and use it to build and deploy container-based apps. No prior knowledge of Docker is expected.

What You Will Learn

  • Develop containerized applications using the Docker version 17.03
  • Build Docker images from containers and launch them
  • Develop Docker images and containers leveraging Dockerfiles
  • Use Docker volumes to share data
  • Get to know how data is shared between containers
  • Understand Docker Jenkins integration
  • Gain the power of container orchestration
  • Familiarize yourself with the frequently used commands such as docker exec, docker ps, docker top, and docker stats

In Detail

Docker is an open source containerization engine that offers a simple and faster way for developing and running software. Docker containers wrap software in a complete filesystem that contains everything it needs to run, enabling any application to be run anywhere – this flexibily and portabily means that you can run apps in the cloud, on virtual machines, or on dedicated servers.

This book will give you a tour of the new features of Docker and help you get started with Docker by building and deploying a simple application. It will walk you through the commands required to manage Docker images and containers. You’ll be shown how to download new images, run containers, list the containers running on the Docker host, and kill them.

You’ll learn how to leverage Docker’s volumes feature to share data between the Docker host and its containers – this data management feature is also useful for persistent data. This book also covers how to orchestrate containers using Docker compose, debug containers, and secure containers using the AppArmor and SELinux security modules.

Style and approach

This step-by-step guide will walk you through the features and use of Docker, from Docker software installation to the impenetrable security of containers.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  2. Getting Started with Docker
    1. The key drivers for Dockerization
    2. Differentiating between containerization and virtualization
      1. The latest additions to the Docker platform
        1. Windows containers
    3. Installing the Docker Engine
      1. Installing Docker on Ubuntu
      2. Installing Docker using an automated script
      3. Installing Docker on the Mac
      4. Installing Docker on Windows
    4. Understanding the Docker setup
      1. Client-server communication
    5. Downloading the first Docker image
    6. Running the first Docker container
      1. Troubleshooting Docker containers
    7. Summary
  3. Handling Docker Containers
    1. Clarifying Docker terms
      1. Docker images
      2. Docker containers
      3. Docker Registry
    2. Working with Docker images
      1. The Docker Hub
      2. Searching Docker images
    3. Working with an interactive container
      1. Tracking changes inside containers
      2. Controlling Docker containers
      3. Housekeeping containers
      4. Building images from containers
      5. Launching a container as a daemon
    4. Summary
  4. Building Images
    1. Docker's integrated image building system
    2. A quick overview of the Dockerfile's syntax
      1. The comment line
      2. The parser directives
    3. The Dockerfile build instructions
      1. The FROM instruction
      2. The MAINTAINER instruction
      3. The COPY instruction
      4. The ADD instruction
      5. The ENV instruction
      6. The ARG instruction
      7. The environment variables
      8. The USER instruction
      9. The WORKDIR instruction
      10. The VOLUME instruction
      11. The EXPOSE instruction
      12. The LABEL instruction
      13. The RUN instruction
      14. The CMD instruction
      15. The ENTRYPOINT instruction
      16. The HEALTHCHECK instruction
      17. The ONBUILD instruction
      18. The STOPSIGNAL instruction
      19. The SHELL instruction
      20. The .dockerignore file
    4. A brief on the Docker image management
    5. Best practices for writing a Dockerfile
    6. Summary
  5. Publishing Images
    1. Understanding Docker Hub
    2. Pushing images to Docker Hub
    3. Automating the build process for images
    4. Private repositories on Docker Hub
    5. Organizations and teams on Docker Hub
    6. The REST API for Docker Hub
    7. Summary
  6. Running Your Private Docker Infrastructure
    1. Docker Registry
    2. Docker Registry use cases
    3. Running Docker Registry and pushing the image
    4. Running the Docker Registry on localhost with an SSL certificate
    5. Running Docker Registry with restrictions
    6. Managing Docker Registry with Docker Compose
    7. Load balancing consideration
    8. Webhook notifications
    9. Docker Registry HTTP API support
    10. Summary
  7. Running Services in a Container
    1. A brief overview of container networking
    2. Envisaging container as a service
      1. Building an HTTP server image
      2. Running the HTTP server image as a service
      3. Connecting to the HTTP service
    3. Exposing container services
      1. Publishing a container's port - the -p option
      2. NAT for containers
      3. Retrieving the container port
      4. Binding a container to a specific IP address
      5. Autogenerating the Docker host port
      6. Port binding using EXPOSE and -P option
    4. Summary
  8. Sharing Data with Containers
    1. Data volume
    2. The volume management command
    3. Sharing host data
      1. The practicality of host data sharing
    4. Sharing data between containers
      1. Data-only containers
      2. Mounting data volume from other containers
      3. The practicality of data sharing between containers
    5. Avoiding common pitfalls
      1. Directory leaks
      2. The undesirable effect of data volume
    6. Summary
  9. Orchestrating Containers
    1. Docker inbuilt service discovery
    2. Linking containers
    3. Orchestration of containers
      1. Orchestrating containers using docker-compose
      2. Installing docker-compose
      3. The docker-compose file
      4. The docker-compose command
      5. Common usage
    4. Summary
  10. Testing with Docker
    1. A brief overview of TDD
    2. Testing your code inside Docker
      1. Running the test inside a container
        1. Using a Docker container as a runtime environment
    3. Integrating Docker testing into Jenkins
      1. Preparing the Jenkins environment
      2. Automating the Docker testing process
    4. Summary
  11. Debugging Containers
    1. Process-level isolation for Docker containers
      1. Control groups
      2. Debugging a containerized application
    2. The docker exec command
    3. The docker ps command
    4. The docker top command
    5. The docker stats command
    6. The Docker events command
    7. The docker logs command
    8. The docker attach command
    9. Debugging a Dockerfile
    10. Summary
  12. Securing Docker Containers
    1. The security scenario in the containerization domain
      1. The security ramifications of Docker containers
      2. The security facets - virtual machines versus Docker containers
      3. The prominent security-fulfilment features of containers
    2. Immutable infrastructure
      1. Resource isolation
        1. Resource accounting and control
      2. The root privilege - impacts and best practices
      3. The trusted user control
        1. Non-root containers
      4. SELinux for container security
        1. Loading the Docker images and the security implications
      5. Image signing and verification using TUF
      6. The emerging security approaches
    3. The best practices for container security
      1. Secure deployment guidelines for Docker containers
      2. The future of Docker security
    4. Summary
  13. The Docker Platform – Distinct Capabilities and Use Cases
    1. Describing containers
      1. Distinguishing Docker containers
    2. Briefing the Docker platform
      1. The evolving Docker platform components
    3. Implications of the Docker technology
      1. Modern enterprise development
      2. MSA and Docker containers
        1. Case study
      3. Infrastructure optimization
        1. Case study
      4. Enabling DevOps
      5. Continuous integration and continuous deployment
      6. Continuous delivery
        1. Accurate testing
        2. Facilitating CaaS
      7. Accelerating workload modernization
        1. Docker for stateful applications
        2. Containers for edge computing
          1. Devices networking, service enablement, and clustering
          2. Device service registry for discovery
          3. Fault tolerance
          4. Caching
    4. The Docker use cases
      1. Integrating containers into workflows
      2. Docker for HPC and TC applications
        1. Containers for telecom applications
    5. Summary