A Developer's Essential Guide to Docker Compose

Book description

Start defining your infrastructure using Docker Compose and leverage it for everyday development or deployment

Key Features

  • Distribute your code in an easier way for developers to get started
  • Set up complex infrastructure for development and CI/CD purposes
  • Deploy simple multi-container applications using Docker Compose

Book Description

Software development is becoming increasingly complex due to the various software components used. Applications need to be packaged with software components to facilitate their operations, making it complicated to run them. With Docker Compose, a single command can set up your application and the needed dependencies.

This book starts with an overview of Docker Compose and its usage and then shows how to create an application. You will also get to grips with the fundamentals of Docker volumes and network, along with Compose commands, their purpose, and use cases. Next, you will set up databases for daily usage using Compose and, leveraging Docker networking, you will establish communication between microservices. You will also run entire stacks locally on Compose, simulate production environments, and enhance CI/CD jobs using Docker Compose. Later chapters will show you how to benefit from Docker Compose for production deployments, provision infrastructure on public clouds such as AWS and Azure, and wrap up with Compose deployments on said infrastructure.

By the end of this book, you will have learned how to effectively utilize Docker Compose for day-to-day development.

What you will learn

  • Create multi-container applications using Docker Compose
  • Use Docker Compose for daily development
  • Connect microservices leveraging Docker network fundamentals
  • Add monitoring to services leveraging Prometheus
  • Deploy to production using Docker Compose
  • Translate Compose files to Kubernetes deployments

Who this book is for

This book is for software engineers, developer advocates, and DevOps engineers looking to set up multi-container Docker applications using Compose without the need to set up a Docker orchestration engine. It is also for team leads looking to increase the productivity of an organization's software teams by streamlining the provisioning of complex development environments locally using Docker Compose. Readers are expected to understand containerization and must possess fundamental Docker knowledge to get started with this book.

Table of contents

  1. A Developer’s Essential Guide to Docker Compose
  2. Contributors
  3. About the author
  4. About the reviewer
  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. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share your thoughts
  6. Part 1: Docker Compose 101
  7. Chapter 1: Introduction to Docker Compose
    1. Technical requirements
    2. Introducing Docker Compose and its usage
    3. Installing Docker Compose
      1. Docker Desktop
      2. Installing Docker
      3. docker compose versus docker-compose
    4. Understanding how Docker Compose works
    5. Your first Docker Compose file
    6. Using your Docker image on Docker Compose
    7. Summary
  8. Chapter 2: Running the First Application Using Compose
    1. Technical requirements
    2. Creating a core application
      1. Installing Go
      2. A REST API in Go using Gin
      3. The application
    3. Running Redis using Compose
    4. Shelling into a container managed by Compose
    5. Interacting with a Docker Compose service
    6. Packaging your application with Docker and Compose
      1. Enabling environment configuration
      2. Docker image creation
      3. Running the image
      4. Build an image using Compose
    7. Running your multi-container application using Compose
      1. Health check
      2. Depending on services
      3. Labels
      4. Images
      5. Containers
    8. Summary
  9. Chapter 3: Network and Volumes Fundamentals
    1. Technical requirements
    2. Explaining Docker volumes
    3. Attaching a Docker volume to a container
      1. Shared volumes
      2. Read-only volumes
    4. Docker volume drivers
      1. Using a volume driver versus mounting locally
    5. Declaring Docker volumes on Compose files
    6. Attaching Docker volumes to an existing application
    7. Creating a configuration file
    8. Mounting a file using volume
      1. Mounting read-only volumes
    9. Docker networking
      1. Bridge
      2. Host
      3. Overlay
    10. Defining networks on a Compose configuration
    11. Adding an extra network to the current application
    12. Summary
  10. Chapter 4: Executing Docker Compose Commands
    1. Technical requirements
    2. Introducing Compose commands
    3. The Docker CLI versus Compose commands
      1. Setting up the target application
    4. Provisioning commands
      1. build
      2. create
      3. up
    5. Container commands
      1. exec
      2. run
      3. pause
      4. unpause
      5. start and stop
      6. restart
      7. kill
      8. ps
    6. Cleanup commands
      1. down
      2. rm
    7. Image commands
      1. List images
      2. Pulling images
      3. Pushing images
      4. Local Docker registry on Compose
      5. Pushing to the local registry
    8. Monitoring commands
      1. Logs
      2. top
      3. Events
    9. Other commands
      1. help
      2. version
      3. port
      4. config
    10. Summary
  11. Part 2: Daily Development with Docker Compose
  12. Chapter 5: Connecting Microservices
    1. Technical requirements
    2. Introducing the location microservice
    3. Adding a location service to Compose
    4. Adding a network for the location microservice
    5. Executing requests to the location microservice
    6. Streaming task events
    7. Adding a task events processing microservice
    8. Summary
  13. Chapter 6: Monitoring Services with Prometheus
    1. What is Prometheus?
    2. Adding an endpoint for Prometheus
      1. Adding the metrics endpoint to the Task Manager
      2. Adding the metrics endpoint to the location service
      3. Exporting metrics from the Event Service
    3. Configuring Prometheus to parse metrics
    4. Adding Prometheus to the Compose network
      1. Pushing metrics to Prometheus
    5. Creating your first metrics query
      1. Adding an alert
    6. Summary
  14. Chapter 7: Combining Compose Files
    1. Technical requirements
    2. Splitting Compose files
      1. Task Manager base
      2. Location service
      3. Event service
      4. Task Manager
      5. Prometheus
    3. Combining Compose files
    4. Selecting the Compose files to run
      1. Using Hoverfly
      2. Extending services
      3. Capturing traffic with Hoverfly
      4. Creating mock applications using Ηoverfly
    5. Creating different environments
      1. Running with capturing enabled
      2. Running with monitoring disabled
      3. Running applications individually
    6. Combining multiple Compose files into one
      1. Using config
    7. Summary
  15. Chapter 8: Simulating Production Locally
    1. Technical requirements
    2. Segregating private and public workloads
    3. Setting up DynamoDB locally
      1. Creating DynamoDB tables
      2. Interacting with the Local DynamoDB
    4. Setting up SQS locally
    5. Setting up S3 locally
    6. Setting up a REST-based Lambda function
    7. Setting up an SQS-based Lambda function
      1. Docker Compose links
    8. Connecting the Lambda functions
    9. Summary
  16. Chapter 9: Creating Advanced CI/CD Tasks
    1. Technical requirements
    2. Introduction to CI/CD
    3. Using Docker Compose with GitHub Actions
      1. Creating your first GitHub Action
      2. Caching built images
      3. Building application images
      4. Testing your Compose application
    4. Using Docker Compose with Bitbucket pipelines
      1. Creating your first Bitbucket pipeline
      2. Caching Compose and Docker images
      3. Building application images
      4. Testing your Compose application
    5. Using Docker Compose with Travis
      1. Creating your first Travis job
      2. Caching Compose
      3. Building application images
      4. Testing your Compose application
    6. Summary
  17. Part 3: Deployment with Docker Compose
  18. Chapter 10: Deploying Docker Compose Using Remote Hosts
    1. Technical requirements
    2. Docker remote hosts
    3. Creating a remote Docker host
      1. Creating a Docker host on AWS EC2
      2. Using the remote Docker host
    4. Docker Contexts
    5. Deploying Compose to remote hosts
    6. Executing remote host deployments through your IDE
    7. Summary
  19. Chapter 11: Deploying Docker Compose to AWS
    1. Technical requirements
    2. Introduction to AWS ECS
    3. Hosting your Docker images on AWS ECR
      1. Provision ECR using AWS CLI
      2. Provision ECR using Terraform
      3. Storing a Terraform state file
      4. Pushing images to ECR
      5. Adapting the Compose application images
    4. Deploying your application to an ECS cluster
    5. Running your Compose application to an existing cluster
      1. Creating a log group
      2. Creating a private network
      3. Security groups
      4. Configuring the ECS cluster and the load balancer
      5. Updating the Compose file
      6. Running your Compose application on existing infrastructure
    6. Advanced Docker Compose concepts on ECS
      1. Updating the application
      2. Scaling the application
      3. Using secrets
    7. Summary
  20. Chapter 12: Deploying Docker Compose to Azure
    1. Technical requirements
    2. An introduction to ACI
    3. Pushing to an Azure container registry
      1. Storing the Terraform state file
    4. Deploying on ACI
    5. Summary
  21. Chapter 13: Migrating to Kubernetes Configuration Using Compose
    1. Technical requirements
    2. Introduction to Kubernetes
    3. Kubernetes components and Compose
      1. Compose applications versus namespaces
      2. Compose services versus Kubernetes services
      3. Labels
      4. Compose networks versus network policies
    4. Using Kompose to convert files
    5. Introduction to Minikube
    6. Deploying to Kubernetes
    7. Summary
  22. Index
    1. Why subscribe?
  23. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share your thoughts

Product information

  • Title: A Developer's Essential Guide to Docker Compose
  • Author(s): Emmanouil Gkatziouras
  • Release date: October 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781803234366