You are previewing Learning Docker.
O'Reilly logo
Learning Docker

Book Description

Optimize the power of Docker to run your applications quickly and easily

In Detail

Docker is a next-generation platform for simplifying application containerization life-cycle. Docker allows you to create a robust and resilient environment in which you can generate portable, composable, scalable, and stable application containers.

This book is a step-by-step guide that will walk you through the various features of Docker from Docker software installation to the impenetrable security of containers. The book starts off by elucidating the installation procedure for Docker and a few troubleshooting techniques. You will be introduced to the process of downloading Docker images and running them as containers. You'll learn how to run containers as a service (CaaS) and also discover how to share data among containers. Later on, you'll explore how to establish the link between containers and orchestrate containers using Docker Compose. You will also come across relevant details about application testing inside a container. You will discover how to debug a container using the docker exec command and the nsenter tool. Finally, you will learn how to secure your containers with SELinux and other proven methods.

What You Will Learn

  • Build a Docker image using Dockerfiles

  • Push and publish images on Docker Hub

  • Run your own private Docker Hub and upload images onto it

  • Create and run services inside a container to deploy your applications with ease

  • Share data between the Docker host and containers

  • Orchestrate multiple containers with Docker Compose

  • Test and debug applications inside a Docker container

  • Secure your Docker containers with SELinux

  • 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 files e-mailed directly to you.

    Table of Contents

    1. Learning Docker
      1. Table of Contents
      2. Learning Docker
      3. Credits
      4. About the Authors
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. 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. Errata
          3. Piracy
          4. Questions
      8. 1. Getting Started with Docker
        1. An introduction to Docker
        2. Docker on Linux
        3. Differentiating between containerization and virtualization
          1. The convergence of containerization and virtualization
          2. Containerization technologies
        4. Installing the Docker engine
          1. Installing from the Ubuntu package repository
          2. Installing the latest Docker using docker.io script
        5. Understanding the Docker setup
          1. Client server communication
        6. Downloading the first Docker image
        7. Running the first Docker container
        8. Running a Docker container on Amazon Web Services
        9. Troubleshooting
        10. Summary
      9. 2. Handling Docker Containers
        1. Clarifying the Docker terms
          1. Docker images and containers
          2. A Docker layer
          3. A Docker container
          4. Docker Registry
          5. Docker Repository
        2. Working with Docker images
          1. Docker Hub Registry
          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
      10. 3. Building Images
        1. Docker's integrated image building system
        2. A quick overview of the Dockerfile's syntax
        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 USER instruction
          7. The WORKDIR instruction
          8. The VOLUME instruction
          9. The EXPOSE instruction
          10. The RUN instruction
          11. The CMD instruction
          12. The ENTRYPOINT instruction
          13. The ONBUILD instruction
          14. The .dockerignore file
        4. A brief overview of the Docker image management
        5. Best practices for writing Dockerfiles
        6. Summary
      11. 4. Publishing Images
        1. Understanding the Docker Hub
        2. Pushing images to the Docker Hub
        3. Automating the building process for images
        4. Private repositories on the Docker Hub
        5. Organizations and teams on the Docker Hub
        6. The REST APIs for the Docker Hub
        7. Summary
      12. 5. Running Your Private Docker Infrastructure
        1. The Docker registry and index
        2. Docker registry use cases
        3. Run your own index and registry
          1. Step 1 – Deployment of the index components and the registry from GitHub
          2. Step 2 – Configuration of nginx with the Docker registry
          3. Step 3 – Set up SSL on the web server for secure communication
        4. Push the image to the newly created Docker registry
        5. Summary
      13. 6. Running Services in a Container
        1. A brief overview of container networking
        2. Envisaging the 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 container ports – the -p option
          2. Network Address Translation for containers
          3. Retrieving the container port
          4. Binding a container to a specific IP address
          5. Auto-generating the Docker host port
          6. Port binding using EXPOSE and the -P option
        4. Summary
      14. 7. Sharing Data with Containers
        1. The data volume
        2. Sharing host data
          1. The practicality of host data sharing
        3. Sharing data between containers
          1. Data-only containers
          2. Mounting data volume from other containers
          3. The practicality of data sharing between containers
        4. Avoiding common pitfalls
          1. Directory leaks
          2. The undesirable effect of data volume
        5. Summary
      15. 8. Orchestrating Containers
        1. Linking containers
        2. Orchestration of containers
          1. Orchestrate containers using docker-compose
          2. Installing docker-compose
          3. The docker-compose.yml file
          4. The docker-compose command
          5. Common usage
        3. Summary
      16. 9. Testing with Docker
        1. A brief overview of the test-driven development
        2. Testing your code inside Docker
          1. Running the test inside a container
          2. 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
      17. 10. Debugging Containers
        1. Process level isolation for Docker containers
          1. Control groups
        2. Debugging a containerized application
          1. The Docker exec command
          2. The Docker ps command
          3. The Docker top command
          4. The Docker stats command
          5. The Docker events command
          6. The Docker logs command
        3. Installing and using nsenter
        4. Summary
      18. 11. Securing Docker Containers
        1. Are Docker containers secure enough?
          1. The security facets – virtual machines versus Docker containers
          2. The security features of containers
            1. Resource isolation
            2. Resource accounting and control
          3. The root privilege – impacts and best practices
            1. The trusted user control
            2. Non-root containers
            3. Loading the Docker images and the security implications
            4. The emerging security approaches
        2. Security-Enhanced Linux for container security
          1. SELinux-inspired benefits
        3. The best practices for container security
        4. Digital signature verification
          1. Secure deployment guidelines for Docker
          2. The future
        5. Summary
      19. Index