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

The Docker Book

Book Description

Designed for SysAdmins, Operations staff, Developers, and DevOps, this book will introduce you to the open source container platform Docker.

In this book, we will walk you through installing, deploying, managing, and extend Docker. We're going to do that by first introducing you to the basics of Docker and its components. Then we'll start to use Docker to build containers and services to perform a variety of tasks.

We're going to take you through the development lifecycle, from testing to production, and see where Docker fits in and how it can make your life easier. We'll make use of Docker to build test environments for new projects, demonstrate how to integrate Docker with continuous integration workflow, and then how to build application services and platforms. Finally, we'll show you how to use Docker's API and how to extend Docker yourself.

We'll teach you how to:

* Install Docker.
* Take your first steps with a Docker container.
* Build Docker images.
* Manage and share Docker images.
* Run and manage more complex Docker containers.
* Deploy Docker containers as part of your testing pipeline.
* Build multi-container applications and environments.
* Learn about orchestration. Use Compose and Swarm for the orchestration of Docker containers and Consul for service discovery.
* Explore the Docker API.
* Getting Help and Extending Docker.

Table of Contents

  1. The Docker Book
    1. 0.1 Who is this book for?
    2. 0.2 A note about versions
    3. 0.3 Credits and Acknowledgments
    4. 0.4 Technical Reviewers
      1. 0.4.1 Scott Collier
      2. 0.4.2 John Ferlito
      3. 0.4.3 Pris Nasrat
    5. 0.5 Technical Illustrator
    6. 0.6 Proofreader
    7. 0.7 Author
    8. 0.8 Conventions in the book
    9. 0.9 Code and Examples
    10. 0.10 Colophon
    11. 0.11 Errata
    12. 0.12 Version
  2. 1 Introduction
    1. 1.1 Introducing Docker
      1. 1.1.1 An easy and lightweight way to model reality
      2. 1.1.2 A logical segregation of duties
      3. 1.1.3 Fast, efficient development life cycle
      4. 1.1.4 Encourages service oriented architecture
    2. 1.2 Docker components
      1. 1.2.1 Docker client and server
      2. 1.2.2 Docker images
      3. 1.2.3 Registries
      4. 1.2.4 Containers
      5. 1.2.5 Compose, Swarm and Kubernetes
    3. 1.3 What can you use Docker for?
    4. 1.4 Docker with configuration management
    5. 1.5 Docker’s technical components Docker’s technical components
    6. 1.6 What’s in the book? What’s in the book?
    7. 1.7 Docker resources
  3. 2 Installing Docker
    1. 2.1 Requirements
    2. 2.2 Installing on Ubuntu and Debian
      1. 2.2.1 Checking for prerequisites
      2. 2.2.2 Installing Docker
      3. 2.2.3 Docker and UFW
    3. 2.3 Installing on Red Hat and family
      1. 2.3.1 Checking for prerequisites
      2. 2.3.2 Installing Docker
      3. 2.3.3 Starting the Docker daemon on the Red Hat family
    4. 2.4 Docker for Mac
      1. 2.4.1 Installing Docker for Mac
      2. 2.4.2 Testing Docker for Mac
    5. 2.5 Docker for Windows installation
      1. 2.5.1 Installing Docker for Windows
      2. 2.5.2 Testing Docker for Windows
    6. 2.6 Using Docker on OSX and Windows with this book
    7. 2.7 Docker installation script
    8. 2.8 Binary installation
    9. 2.9 The Docker daemon
      1. 2.9.1 Configuring the Docker daemon
      2. 2.9.2 Checking that the Docker daemon is running
    10. 2.10 Upgrading Docker
    11. 2.11 Docker user interfaces
    12. 2.12 Summary
  4. 3 Getting Started with Docker
    1. 3.1 Ensuring Docker is ready
    2. 3.2 Running our first container
    3. 3.3 Working with our first container
    4. 3.4 Container naming
    5. 3.5 Starting a stopped container
    6. 3.6 Attaching to a container
    7. 3.7 Creating daemonized containers
    8. 3.8 Seeing what’s happening inside our container Seeing what’s happening inside our container
    9. 3.9 Docker log drivers
    10. 3.10 Inspecting the container’s processes Inspecting the container’s processes
    11. 3.11 Docker statistics
    12. 3.12 Running a process inside an already running container
    13. 3.13 Stopping a daemonized container
    14. 3.14 Automatic container restarts
    15. 3.15 Finding out more about our container
    16. 3.16 Deleting a container
    17. 3.17 Summary
  5. 4 Working with Docker images and repositories
    1. 4.1 What is a Docker image?
    2. 4.2 Listing Docker images
    3. 4.3 Pulling images
    4. 4.4 Searching for images
    5. 4.5 Building our own images
      1. 4.5.1 Creating a Docker Hub account
      2. 4.5.2 Using Docker commit to create images
      3. 4.5.3 Building images with a Dockerfile
      4. 4.5.4 Building the image from our Dockerfile
      5. 4.5.5 What happens if an instruction fails?
      6. 4.5.6 Dockerfiles and the build cache
      7. 4.5.7 Using the build cache for templating
      8. 4.5.8 Viewing our new image
      9. 4.5.9 Launching a container from our new image
      10. 4.5.10 Dockerfile instructions
    6. 4.6 Pushing images to the Docker Hub
      1. 4.6.1 Automated Builds
    7. 4.7 Deleting an image
    8. 4.8 Running your own Docker registry
      1. 4.8.1 Running a registry from a container
      2. 4.8.2 Testing the new registry
    9. 4.9 Alternative Indexes
      1. 4.9.1 Quay
    10. 4.10 Summary
  6. 5 Testing with Docker
    1. 5.1 Using Docker to test a static website
      1. 5.1.1 An initial Dockerfile for the Sample website
      2. 5.1.2 Building our Sample website and Nginx image
      3. 5.1.3 Building containers from our Sample website and Nginx image
      4. 5.1.4 Editing our website
    2. 5.2 Using Docker to build and test a web application
      1. 5.2.1 Building our Sinatra application
      2. 5.2.2 Creating our Sinatra container
      3. 5.2.3 Extending our Sinatra application to use Redis
      4. 5.2.4 Connecting our Sinatra application to the Redis container
      5. 5.2.5 Docker internal networking
      6. 5.2.6 Docker networking
      7. 5.2.7 Connecting containers summary
    3. 5.3 Using Docker for continuous integration
      1. 5.3.1 Build a Jenkins and Docker server
      2. 5.3.2 Create a new Jenkins job
      3. 5.3.3 Running our Jenkins job
      4. 5.3.4 Next steps with our Jenkins job
      5. 5.3.5 Summary of our Jenkins setup
    4. 5.4 Multi-configuration Jenkins
      1. 5.4.1 Create a multi-configuration job
      2. 5.4.2 Testing our multi-configuration job
      3. 5.4.3 Summary of our multi-configuration Jenkins
    5. 5.5 Other alternatives
      1. 5.5.1 Drone
      2. 5.5.2 Shippable
    6. 5.6 Summary
  7. 6 Building services with Docker
    1. 6.1 Building our first application
      1. 6.1.1 The Jekyll base image
      2. 6.1.2 Building the Jekyll base image
      3. 6.1.3 The Apache image
      4. 6.1.4 Building the Jekyll Apache image
      5. 6.1.5 Launching our Jekyll site
      6. 6.1.6 Updating our Jekyll site
      7. 6.1.7 Backing up our Jekyll volume
      8. 6.1.8 Extending our Jekyll website example
    2. 6.2 Building a Java application server with Docker
      1. 6.2.1 A WAR file fetcher
      2. 6.2.2 Fetching a WAR file
      3. 6.2.3 Our Tomcat 7 application server
      4. 6.2.4 Running our WAR file
      5. 6.2.5 Building on top of our Tomcat application server
    3. 6.3 A multi-container application stack
      1. 6.3.1 The Node.js image
      2. 6.3.2 The Redis base image
      3. 6.3.3 The Redis primary image
      4. 6.3.4 The Redis replica image
      5. 6.3.5 Creating our Redis back-end cluster
      6. 6.3.6 Creating our Node container
      7. 6.3.7 Capturing our application logs
      8. 6.3.8 Summary of our Node stack
    4. 6.4 Managing Docker containers without SSH
    5. 6.5 Summary
  8. 7 Docker Orchestration and Service Discovery
    1. 7.1 Docker Compose
      1. 7.1.1 Installing Docker Compose
      2. 7.1.2 Getting our sample application
      3. 7.1.3 The docker-compose.yml file
      4. 7.1.4 Running Compose
      5. 7.1.5 Using Compose
      6. 7.1.6 Compose in summary
    2. 7.2 Consul, Service Discovery and Docker
      1. 7.2.1 Building a Consul image
      2. 7.2.2 Testing a Consul container locally
      3. 7.2.3 Running a Consul cluster in Docker
      4. 7.2.4 Starting the Consul bootstrap node
      5. 7.2.5 Starting the remaining nodes
      6. 7.2.6 Running a distributed service with Consul in Docker
    3. 7.3 Docker Swarm
      1. 7.3.1 Understanding the Swarm
      2. 7.3.2 Installing Swarm
      3. 7.3.3 Setting up a Swarm
      4. 7.3.4 Running a service on your Swarm
    4. 7.4 Orchestration alternatives and components
      1. 7.4.1 Fleet and etcd
      2. 7.4.2 Kubernetes
      3. 7.4.3 Apache Mesos
      4. 7.4.4 Helios
      5. 7.4.5 Centurion
    5. 7.5 Summary
  9. 8 Using the Docker API
    1. 8.1 The Docker APIs
    2. 8.2 First steps with the Engine API
    3. 8.3 Testing the Docker Engine API
      1. 8.3.1 Managing images with the API
      2. 8.3.2 Managing containers with the API
    4. 8.4 Improving the TProv application
    5. 8.5 Authenticating the Docker Engine API
      1. 8.5.1 Create a Certificate Authority
      2. 8.5.2 Create a server certificate signing request and key
      3. 8.5.3 Configuring the Docker daemon
      4. 8.5.4 Creating a client certificate and key
      5. 8.5.5 Configuring our Docker client for authentication
    6. 8.6 Summary
  10. 9 Getting help and extending Docker
    1. 9.1 Getting help
      1. 9.1.1 The Docker forums
      2. 9.1.2 Docker on IRC
      3. 9.1.3 Docker on GitHub
    2. 9.2 Reporting issues for Docker
    3. 9.3 Setting up a build environment
      1. 9.3.1 Install Docker
      2. 9.3.2 Install source and build tools
      3. 9.3.3 Check out the source
      4. 9.3.4 Contributing to the documentation
      5. 9.3.5 Build the environment
      6. 9.3.6 Running the tests
      7. 9.3.7 Use Docker inside our development environment
      8. 9.3.8 Submitting a pull request
      9. 9.3.9 Merge approval and maintainers
    4. 9.4 Summary