Docker
The ultimate beginners guide to learn Docker step-by-step
Mark Reed
Copyright 2019 - All rights reserved.
It is not legal to reproduce, duplicate, or transmit any part of this document in either electronic means or in printed format. Recording of this publication is strictly prohibited and any storage of this document is not allowed unless with written permission from the publisher except for the use of brief quotations in a book review.
Table of Contents
Introduction
The age of virtualization has done a lot for allowing developers to build and create from their computers as if they were different systems. Virtual machines allow them to create entirely virtual operating systems within which to work and build. These systems are one of the major ways through which a homogenization process has been able to spread through the development world. A developer can run a Windows virtual machine from their Macbook in order to test the functionality of an app that was designed for Windows. It is far cheaper and easier to run a virtual machine than it is to buy a whole new computer.
Yet even virtual machines bring with them their own set of difficulties. There are many factors which determine how efficient a virtual machine will be on any given computer. Then, on top of that, each computer uses different hardware like graphics cards and processors. Two different Macbooks may each be able to run a Windows virtual machine but the underlying hardware has a direct effect on how well the app inside the virtual machine will run. So, while virtual machines have started a homogenization process, they are still far from completing it.
Thats where Docker comes in. Docker is a platform as a service product which uses operating system level virtualization so that users can utilize software in packages which are called containers. Each container is isolated from each other and includes everything that the end user needs to run the software on their computer regardless of its specs. Theyre more lightweight than virtual systems and remove a lot of the guesswork from the virtualization process. Since Dockers creation in 2013, it has been used and expanded on by companies like Microsoft, Google, IBM, Huawei, Cisco and more. In fact, the use of Docker is spreading so quickly that an analysis of LinkedIn profiles in 2017 showed that mentions of the application went up almost 200% in 2016 alone.
So many people are finding that Docker is the perfect tool to solve their DevOps tasks that its continued adoption across industries and specializations shows no sign of slowing down. Chances are you found this book because youve already identified Docker as a potential tool for the problems that you face. The aim of this text is to give beginners everything they need to start using Docker themselves. To achieve this goal, this book is divided into two parts. The first part is the explanatory text which teaches you the concepts and steps that you need in order to use Docker. The second part is the exercises and hands-on training tasks which allow you to get started working in Docker to put what youve learned into motion. These exercises will be spread out throughout the book so that you can get right into them alongside the relevant sections.
The book is broken up into chapters which each focus on a specific element of Docker. Chapter One explores more of what Docker is and how and why it solves the problems mentioned above. Well also learn what a Dockerfile, an image and a container is in this chapter.
Chapter Two will take you through setting up Docker on your own computer. There are some key differences in how Docker functions when it is run on Linux, Windows or Mac and well see what these differences are. Youll also run your first container in this chapter and see just how easy the process is.
Chapter Three will cover how we containerize an application. That is, how do we turn an application into an image which can be opened as a container so that we can share our apps with other Docker users. Well take a look at how we deploy these applications and how we can share them with the wider Docker user base.
Chapter Four looks at networking with Docker. This covers how you can connect Docker containers together or even to non-Docker workloads in order to really make use of the full power of the Docker service.
By the end of the book, youll be able to turn your applications into containers, share or run them through Docker and connect them to other containers and see just how powerful Docker really is. This is only a beginners guide, so the more advanced topics arent going to be covered here but everything you need to know to get started with Docker today is in your hands right now.
Chapter One:
Understanding Docker, Containers, Images and Dockerfiles
Docker can be a bit of a confusing program to understand if youve never worked with virtualization before. In order to clear up any confusion around Docker, let us take a look at what it is and why it exists. This will help you to decide if Docker is right for you or not. From there well look at the various components of Docker to understand what they are so that when we start using them in the following chapters there will be no confusion surrounding what each component does.
What is Docker?
Docker first launched back in 2013 after several years of development. At its core, Docker is a tool designed to make it easier to run applications throughout the DevOps process. Docker is like a virtual machine in that it runs on a computer but acts like it is its own computer. This allows for users to create, deploy and run applications through the use of containers, the main building block of Docker. Every piece of an application that is needed to run is included within a container, such as libraries and various dependencies, and this allows Docker to run those containers as if they were their own system. Whats more, this allows for Docker containers to be shipped out to other users with everything they need to run the container included.
Docker is an open source platform, too. This means that anyone who wants to can contribute to Docker and use it to fit their own needs. If they find that Docker doesnt have a feature which they require, they can open up the program and add the features they want without having to worry about breaking any laws.
Docker enables users to separate their applications from the hardware and infrastructure they have in place to speed up delivery. Infrastructure can be managed in the same way that applications are. Together with the flexibility of the open source nature, this makes Docker a powerful tool in speeding up the shipping, testing and deployment of code to reduce time between creating it and testing it.
In action, what this looks like is as follows. The user uses Docker to download or open up an image file. This file is then deployed as a container. That container itself is a self-contained application. Instead of running a virtual machine in order to then run the application, the application itself is run like a virtual machine and the user can see if it works or not by whether or not it is working. This sounds redundant but it is an important note. If run in a virtual machine, the application not working may be tied to the virtual machine or the underlying hardware and so there are many reasons it may not work. In Docker, it doesnt work if there is an issue with the application itself.
With the What of Docker out of the way, lets turn now to the Why: Why is Docker gaining such attention in DevOps and the problems it solves.