Copyright
Published by Savalera Kft.
Copyright 2019 Mrk Takcs
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, without the prior permission in writing of the publisher.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Savalera Kft., and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Savalera Kft. has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Savalera Kft. cannot guarantee the accuracy of this information.
The publisher is not responsible for websites (or their content) that are not owned by the publisher.
Savalera Kft.
1112 Tberek u. 8
Budapest, Hungary.
savalera.com, takacsmark.com
Preface
Dear Reader,
Welcome to Get Started with Docker in your Projects!
Im sure you are as excited as I am about your new learning journey in the Docker world.
I wrote this book to give you a practical, step by step learning experience, where you start from the basics and develop your Docker skills building working examples that resemble real-life project situations.
First, in the introduction chapter, I explain what Docker is and what problems it solves in software development projects.
Next, well install Docker on your machine and start building together. I built every chapter in the book on code-along examples.
I recommend you to read the book and build the examples in parallel. You can copy and paste the commands from the book to your command line and code editor, or you can use the code base that I supplied in a separate zip file.
We start the journey by running applications in Docker containers. Ill show you how to start and manage your applications with Docker. I added a chapter to demonstrate practices that are crucial for Dockerized project work.
As a next step, we dive into Docker images, and see how images define containers. Again, well have a project focus, and Ill show you the practices to find and select the best Docker images for your projects online.
As you progress with Docker image learning, youll create your custom Docker images with the Dockerfile, learn Dockerfile best practices, and Ill show you my image building workflow.
Docker containers and Docker images are the foundation of Docker-based projects; therefore I have included a long chapter called Image building exercises at this point, where well build and run applications with shell scripts, Node.js, Python, PHP, C, and Golang. I have included crucial aspects of Docker into these examples that youll find valuable in project work.
After completing the above exercises, youll have a firm understanding of Docker concepts, Docker containers, and Docker images.
Next, well dive into multi-container applications, where multiple containers work together to provide application functionality. Ill show you how you can define, build and run applications with the Docker Compose tool, plus, well learn about Docker Networks and Docker Volumes in this part of the book in greater detail. I also included a chapter to show you build practices with Compose.
The chapters so far in the book targeted build activities in Docker-based projects. Youll learn how to start and manage containers, how to build Docker images for projects, how to build and manage multi-container applications, manage networks and volumes.
I have included a build summary chapter at this point, where I give you an overview of project tasks in the build phase, and youll get a graphical outline of the build workflow.
Now youll be ready to learn how to ship your applications once they are built. Well see how to ship your applications Docker images to the Docker Hub, well set up an automatic build workflow involving GitHub, and youll set up your own Docker Registry, too. Well also see a CI example later in the book.
Similarly to the build summary chapter, I have added a ship summary chapter to outline the shipping workflow in Dockerized projects.
Next, well learn how to run your applications in production. We will run applications in the first chapters, too, but in the run part of the book, well focus on high availability, scalable production run.
Youll learn how to setup and manage a Docker Swarm cluster, how to deploy your application stacks to the Swarm, and how to scale and manage services in a Swarm.
Well start with cluster deployments on your local machine, first with one machine, and then well set up two machines locally and create a Swarm cluster. Well learn how to deploy and manage applications on multiple nodes, and well learn how to manage nodes in a Swarm cluster.
Well deploy our application to the cloud in the next chapters.
Again, youll have a run summary chapter with an overview of typical run tasks in your projects.
At this point, you will have solid Docker skills. You shall be ready to address more complex challenges.
To make you more fluent in Docker, I have included an end to end example where well Dockerize a Flask application, and well use all the learning in the book, plus well add more tricks and best practices.
Well take a popular Flask web application boilerplate project from GitHub and extend it so that we will use Docker to build, ship and run the application.
In this exercise, well use Docker containers to generate the application code. Well use environment variables to drive various aspects of our project build, just like in real-life projects. Well automate most of the project tasks.
We set up the development environment and automated testing using Travis CI. We also prepare the production Docker configuration for the project.
Once the project setup is complete, well deploy and run the web application on AWS in a Swarm cluster, and in a Kubernetes cluster, too.
I have set up the examples to be gradual with a gentle learning curve. I explain the steps in detail so that you can follow along.
I hope youll enjoy the journey and acquire great skills.
Corrections
I have taken meticulous care to ensure the accuracy of the content. Still, you may find mistakes in the text or code. If you see any errata, please contact me at mark.takacs@savalera.com or mark@takacsmark.com.
Downloads
If you bought the book on Amazon or the iBooks Store, please download the code files here.
Introduction
Let me give you a short introduction to the big picture without examples now, and well go through all of the points again with examples in later chapters.
What is Docker?
Docker is a tool that lets you build, ship, and run your applications in containers.
You usually meet Docker when you are about to ship your application to a new machine, and you need a reliable tool to ship your applications technical environment along with your code.
You can also meet Docker when you need an easy way to set up a new technical environment for a project.