Troubleshooting Docker - Vaibhav Kohli - E-Book

Troubleshooting Docker E-Book

Vaibhav Kohli

0,0
34,79 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

You?re pro Docker? You?ve read all about orchestration with Docker in books? Now learn how to troubleshoot Docker in practice. Gain all the tools to safely see Docker in action with this 2017 book.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 260

Veröffentlichungsjahr: 2017

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Troubleshooting Docker
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Why subscribe?
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Understanding Container Scenarios and an Overview of Docker
Decoding containers
OS containers
Application containers
Diving into Docker
Advantages of Docker containers
Docker lifecycle
Docker design patterns
Base image sharing
Shared volume
Development tools container
Test environment containers
The build container
The installation container
The service-in-a-box container
Infrastructure containers
Unikernels
Summary
2. Docker Installation
Installing Docker on Ubuntu
Prerequisites
Updating package information
Adding a new GPG key
Troubleshooting
Adding a new package source for Docker
Updating Ubuntu packages
Install linux-image-extra
Optional - installing AppArmor
Docker installation
Installing Docker on Red Hat Linux
Checking kernel version
Updating the YUM packages
Adding the YUM repository
Installing the Docker package
Starting the Docker service
Testing the Docker installation
Checking the installation parameters
Troubleshooting tips
Deploy CentOS VM on AWS to run Docker containers
Checking kernel version
Updating the YUM packages
Adding the YUM repository
Installing the Docker package
Starting the Docker service
Testing the Docker installation
Checking the installation parameters
Installing Docker on CoreOS
Installation channels of CoreOS
Troubleshooting
Installing Docker on Fedora
Checking Linux kernel Version
Installing with DNF
Adding to the YUM repository
Installing the Docker package
Installing Docker with script
Running the Docker installation script
Installing Docker on SUSE Linux
Launching the SUSE Linux VM on AWS
Checking Linux kernel version
Adding Containers-Module
Installing Docker
Starting Docker service
Checking the Docker installation
Troubleshooting
Summary
3. Building Base and Layered Images
Building container images
Official images from the Docker Registry
User repositories
Building our own base images
Building images using the scratch repository
Building layered images
Building layered images using Dockerfiles
Dockerfile construction
Dockerfile commands and syntax
Image testing and debugging
Docker details for troubleshooting
Docker version
Docker info
A troubleshooting note for Debian/Ubuntu
Listing installed Docker images
Manually crank your Docker image
Examining the filesystem state from cache
Image layer IDs as debug containers
Additional example
Checking failed container processes
Other potentially useful resources
Using sysdig to debug
Single step installation
Advanced installation
What are chisels?
Troubleshooting - an open community awaits you
Automated image building
Unit tested deployments
Automating tested deployments
Summary
4. Devising Microservices and N-Tier Applications
Hype or hubris
Monolithic architecture
N-tier application architecture
Building a three-tier web application
Microservices architecture
The path to modernity
Microservices architectural pattern
Common characteristics of microservices
Advantages of microservices
Microservices at scalability
Disadvantages of microservices
Considerations for devising microservices
Mitigating the disadvantages
Managing microservices
Real-world example
Automated tests and deployments
Automated testing
Designing for failure
Dockunit for unit tests
Automated deployments
Decoupling N-tier applications into multiple images
Building an N-tier web application
Making different tiers of applications work
Summary
5. Moving Around Containerized Applications
Redistributing via Docker registry
Docker public repository (Docker Hub)
Private Docker registry
Pushing images to Docker Hub
Installing a private local Docker registry
Moving images in between hosts
Ensuring integrity of images - signed images
Docker Trusted Registry (DTR)
Docker Universal Control Plane
Summary
6. Making Containers Work
Privileged containers
Troubleshooting tips
Super-privileged container
Troubleshooting - Docker containers at scale
Puppet
Images
Containers
Networking
Docker compose
Troubleshooting tips
Ansible
Automating Docker with Ansible
Ansible Container
Troubleshooting tips
Chef
Summary
7. Managing the Networking Stack of a Docker Container
Docker networking
docker0 bridge
Troubleshooting Docker bridge configuration
Connecting containers to the external world
Reaching containers from the outside world
Configuring DNS
Troubleshooting communication between containers and the external network
Restricting SSH access from one container to another
Linking containers
libnetwork and the Container Network Model
CNM objects
Sandbox
Endpoint
Network
Network controller
CNM attributes
CNM life cycle
Docker networking tools based on overlay and underlay networks
Flannel
Weave
Project Calico
Configuring an overlay network with the Docker Engine swarm node
Comparison of all multi-host Docker networking solutions
Configuring OpenvSwitch (OVS) to work with Docker
Troubleshooting OVS single host setup
Troubleshooting OVS multiple host setups
Summary
8. Managing Docker Containers with Kubernetes
Deploying Kubernetes on Bare Metal machine
Troubleshooting the Kubernetes Fedora manual setup
Deploying Kubernetes using Minikube
Deploying Kubernetes on AWS
Deploying Kubernetes on vSphere
Kubernetes setup troubleshooting
Kubernetes pod deployment
Deploying Kubernetes in a production environment
Debugging Kubernetes issues
Summary
9. Hooking Volume Baggage
Avoiding troubleshooting by understanding Docker volumes
Default case storing data inside the Docker container
Data-only container
Creating a data-only container
Sharing data between the host and the Docker container
Host mapped volume backed up by shared storage
Flocker
In the Flocker client node
Convoy Docker volume plugin
Docker storage driver performance
UFS basics
UFS - terminology
UFS - issues
AuFS
Device Mapper
How device-mapper is used by Docker
BTRFS
Summary
10. Docker Deployment in a Public Cloud - AWS and Azure
Architecture of Amazon ECS
Troubleshooting - AWS ECS deployment
Updating Docker containers in the ECS cluster
Microsoft Azure container service architecture
Troubleshooting - The Microsoft Azure Container Service
Docker Beta for AWS and Azure
Summary

Troubleshooting Docker

Troubleshooting Docker

Copyright © 2017 Packt Publishing

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 written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

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 authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: March 2017

Production reference: 1280317

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham 

B3 2PB, UK.

ISBN 978-1-78355-234-4

www.packtpub.com

Credits

Authors

Vaibhav Kohli

Rajdeep Dua

John Wooten

Copy Editors

Shaila Kusanale

Safis Editing

Reviewer

Radhakrishna Nayak

Project Coordinator

Ritika Manoj

Commissioning Editor

Vedika Naik

Proofreader

Safis Editing

Acquisition Editor

Tushar Gupta

Indexer

Tejal Daruwale Soni

Content Development Editors

Johann Barretto

Divij Kotian

Production Coordinator

Aparna Bhagat

Technical Editors

Murtaza Tinwala

Sushant Nadkar

Graphics

Jason Monteiro

About the Authors

Vaibhav Kohli at present is working in VMware's R&D Department and earlier taught computer engineering for a year at the esteemed University of Mumbai. He works for the office of the CTO, VMware IoT (Internet of Things) project. He has published many research papers in leading journals, IEEE transactions, and has filed patents at VMware on container technology. One of his big data projects has won the top prize at the national-level project showcase event. He has conducted workshops, hackathons, training sessions, and trade shows in many countries and is a reputed & established speaker at conferences on IoT and Docker technology. He is an active open source code contributor, repository manager and has also published many online Docker & Kubernetes tutorials. He has helped many customers and organizations to understand cloud-native apps, DevOps model and migrate to micro-service architecture. He has also recently published a book on Docker Networking.

Vaibhav manages and leads various meetup groups across India on the latest cutting-edge Docker and Kubernetes technologies.

First and foremost, I would like to thank God for providing me the gift of writing. I dedicate this book to my mom & dad, Kamni Kohli & Ashok K Kohli, who have supported me in everything I have ever done. A special thanks to all my mentors who helped shape me into the person that I am…

Rajdeep Dua has over 18 years of experience in the Cloud and Big Data space. He has worked extensively on Cloud Infrastructure and Machine Learning related projects as well evangelized these stacks at Salesforce, Google, VMWare. Currently, he leads Developer Relations team at Salesforce India. He also works with the Machine Learning team at Salesforce.

He has been nominated by Docker as a Docker Captain for his contributions to the community. His contributions to the open source community are in the following projects: Docker, Kubernetes, Android, OpenStack, and Cloud Foundry. He also has teaching experience in Cloud and Big Data at IIIT Hyderabad, ISB, IIIT Delhi, and College of Engineering Pune.

Rajdeep did his MBA in IT and Systems from Indian Institute of Management Lucknow, India, and BTech from Thapar University, Patiala, India. You can reach him on Twitter at @rajdeepdua.

John Wooten is the founder and CEO of CONSULTED, a global open source cloud consultancy that designs secure, succinct, and sustainable cloud architectures. As a leading cloud solutions architect and open technology strategist, John has deep and applicable real-world experience in designing, testing, deploying, and managing public, private, and hybrid cloud systems for both enterprise and government. His primary technical proficiencies include Linux systems administration, OpenStack clouds, and Docker containers. As an open source activist, John is committedly passionate and works extensively within a broad range of open source projects and communities. His latest Internet project is as the founder and maintainer of ÖppenSourced (www.öppensourced.com), a leading repository and defining resource on open source projects and applications. Otherwise, he is a self-proclaimed beach bum in search of the next surfable wave or is hiking and camping in remote locations.

About the Reviewer

Radhakrishna Nayak is a free software evangelist and works as a senior software engineer at Plivo. He has over 5 years of experience. He is a full stack developer and has worked on various open source technologies, such as Python, Django, AngularJS, ReactJS, HTML5, CSS3, MySQL, MongoDB, PostgreSQL, Docker, and many more. He loves to explore and try out new technologies. He is a foodie and loves to explore new restaurants and ice cream parlors.

I would like to thank my parents, Sudheer Nayak and Vranda Nayak, for all their support and freedom to follow my passion. Thanks to all my colleagues at Plivo and Gautham Pai, founder of Jnaapti, for all their support and encouragement. Thanks to Nikhil, Ritika, and the team at Packt Publishing for trusting my abilities and giving the an opportunity to review this book.

www.PacktPub.com

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www.packtpub.com/mapt

Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Customer Feedback

Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/Troubleshooting-Docker-John-Wooten/dp/1783552344.

If you'd like to join our team of regular reviewers, you can e-mail us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products!

Preface

Docker is an open source, container-based platform that enables anyone to consistently develop and deploy stable applications anywhere. Docker delivers speed, simplicity, and security in creating scalable and portable environments for ultramodern applications. With the advent and prevalence of Docker in the containerization of modern microservices and N-tier applications, it is both prudent and imperative to effectively troubleshoot automated workflows for production-level deployments.

What this book covers

Chapter 1, Understanding Container Scenarios and an Overview of Docker, is about the basic containerization concept with the help of application and OS-based containers. We will throw some light on the Docker technology, its advantages, and the life cycle of Docker containers.

Chapter 2, Docker Installation, will go over the steps to install Docker on various Linux distributions – Ubuntu, CoreOS, CentOS, Red Hat Linux, Fedora, and SUSE Linux.

Chapter 3, Building Base and Layered Images, teaches that a mission-critical task in production-ready application containerization is image building. We will also discuss building images manually from scratch. Moving ahead, we will explore building layered images with a Dockerfile and enlist the Dockerfile commands in detail.

Chapter 4, Devising Microservices and N-Tier Applications, will explore example environments designed seamlessly from development to test, eliminating the need for manual and error-prone resource provisioning and configuration. In doing so, we will touch briefly on how a microservice applications can be tested, automated, deployed, and managed.

Chapter 5, Moving Around Containerized Application, will take a look at Docker registry. We will start with the basic concepts of Docker public repository using Docker Hub and the use case of sharing containers with a larger audience. Docker also provides the option to deploy a private Docker registry, which we look into, that can be used to push, pull, and share the Docker containers internally in the organization.

Chapter 6, Making Containers Work, will teach you about privileged containers, which have access to all the host devices, and super-privileged containers, which show that the containers can run a background service that can be used to run services in Docker containers to manage the underlying host.

Chapter 7, Managing the Networking Stack of a Docker Container, will explain how Docker networking is powered with Docker0 bridge and its troubleshooting issues and configuration. We will also look at troubleshooting the communication issues between Docker networks and the external network. We look into containers communication across multiple hosts using different networking options, such as Weave, OVS, Flannel, and Docker's latest overlay network. We will compare them and look at the troubleshooting issues involved in their configuration.

Chapter 8, Managing Docker Containers with Kubernetes, explains how to manage Docker containers with help of Kubernetes. We will cover many deployment scenarios and troubleshooting issues while deploying Kubernetes on a Bare Metal machine, AWS, vSphere, or using minikube. We will also look at deploying Kubernetes pods effectively and debugging Kubernetes issues.

Chapter 9, Hooking Volume Baggage, will dive into data volumes and storage driver concepts related to Docker. We will discuss troubleshooting the data volumes with the help of the four approaches and look at their pros and cons. The first case of storing data inside the Docker container is the most basic case, but it doesn't provide the flexibility to manage and handle data in the production environment. The second and third cases are about storing the data using data-only containers or directly on the host. The fourth case is about using a third-party volume plugin, Flocker or Convoy, which stores the data in a separate block and even provides reliability with data, even if the container is transferred from one host to another or if the container dies.

Chapter 10, Docker Deployment in a Public Cloud - AWS and Azure, outlines Docker deployment on the Microsoft Azure and AWS public clouds.

What you need for this book

You will need Docker 1.12+ installed on Windows, Mac OS,or Linux machines. Public cloud accounts of AWS, Azure and GCE might be required, which are mentioned in the respective sections of the chapters.

Who this book is for

This book is intended to help seasoned solutions architects, developers, programmers, system engineers, and administrators troubleshoot common areas of Docker containerization. If you are looking to build production-ready Docker containers for automated deployment, you will be able to master and troubleshoot both the basic functions and the advanced features of Docker. Advanced familiarity with the Linux command line syntax, unit testing, the Docker registry, GitHub, and leading container hosting platforms and Cloud Service Providers (CSP) are the prerequisites. In this book you will also learn about ways and means to avoid troubleshooting in the first place. 

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Restart the cluster using the start_k8s.sh shell script."

A block of code is set as follows:

ENTRYPOINT /usr/sbin/sshd -D VOLUME ["/home"] EXPOSE 22 EXPOSE 8080

Any command-line input or output is written as follows:

Docker build -t username/my-imagename -f /path/Dockerfile

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Specify the Stack name, KeyPair, and cluster 3."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book 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.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Troubleshooting-Docker. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.

Chapter 1. Understanding Container Scenarios and an Overview of Docker

Docker is one of the most recent successful open source projects which provides the packaging, shipping, and running of any application as lightweight containers. We can actually compare Docker containers to shipping containers that provide a standard, consistent way of shipping any application. Docker is a fairly new project and with the help of this book it will be easy to troubleshoot some of the common problems which Docker users face while installing and using Docker containers.

In this chapter, the emphasis will be on the following topics:

Decoding containersDiving into DockerThe advantages of Docker containersDocker lifecycleDocker design patternsUnikernels

Decoding containers

Containerization is an alternative to a virtual machine, which involves the encapsulation of applications and providing it with its own operating environment. The basic foundation for containers is Linux Containers (LXC) which is a user space interface for Linux kernel containment features. With the help of powerful API and simple tools, it lets Linux users create and manage application containers. LXC containers are in-between chroot and a fully-fledged virtual machine. Another key difference between containerization and traditional hypervisors is that containers share the Linux kernel used by the operating system running the host machine, thus multiple containers running in the same machine use the same Linux kernel. It gives the advantage of being fast with almost zero performance overhead compared to VMs.

Major use cases of containers are listed in the following sections.

OS containers

OS containers can be easily imagined as a Virtual Machine (VM) but unlike a VM they share the kernel of the host operating system but provide user space isolation. Similar to a VM, dedicated resources can be assigned to containers and we can install, configure, and run different applications, libraries, and so on, just as you would run on any VM. OS containers are helpful in case of scalability testing where a fleet of containers can be deployed easily with different flavors of distros, which is much less expensive compared to the deployment of VMs. Containers are created from templates or images that determine the structure and contents of the container. It allows you to create a container with the identical environment, same package version, and configuration across all containers mostly used in the case of development environment setups.

There are various container technologies such as LXC, OpenVZ, Docker, and BSD jails which are suitable for OS containers:

An OS-based container

Application containers

Application containers are designed to run a single service in the package, while OS containers which were explained previously, can support multiple processes. Application containers are attracting a lot of attraction after the launch of Docker and Rocket.

Whenever a container is launched, it runs a single process. This process runs an application process, but in the case of OS containers it runs multiple services on the same OS. Containers usually have a layered approach as in the case of Docker containers, which helps with reduced duplication and increased re-use. Containers can be started with a base image common to all components and then we can go on adding layers in the file system that are specific to the component. A layered file system helps to rollback changes as we can simply switch to old layers if required. The run command which is specified in Dockerfile adds a new layer for the container.

The main purpose of application containers is to package different components of the application in separate containers. The different components of the application are packaged separately in containers then they interact with help of APIs and services. The distributed multi-component system deployment is the basic implementation of microservice architecture. In the preceding approach, a developer gets the freedom to package the application as per their requirement and the IT team gets the privilege to deploy the container on multiple platforms in order to scale the system both horizontally as well as vertically:

Note

A hypervisor is a Virtual Machine Monitor (VMM), used to allow multiple operating systems to run and share the hardware resources from the host. Each virtual machine is termed as a guest machine.

Docker layers

The following simple example explains the difference between application containers and OS containers:

Let's consider the example of web three-tier architecture. We have a database tier such as MySQL or Nginx for load balancing and the application tier is Node.js:

An OS container

In the case of an OS container, we can pick up by default Ubuntu as the base container and install services MySQL, nginx, and Node.js using Dockerfile. This type of packaging is good for a testing or development setup where all the services are packaged together and can be shipped and shared across developers. But deploying this architecture for production cannot be done with OS containers as there is no consideration of data scalability and isolation. Application containers help to meet this use case as we can scale the required component by deploying more application-specific containers and it also helps to meet load balancing and recovery use cases. For the previous three-tier architecture, each of the services will be packaged into separate containers in order to fulfill the architecture deployment use case:

Application containers scaled up

The main differences between OS and application containers are:

OS Container

Application Container

Meant to run multiple services on the same OS container

Meant to run a single service

Natively, no layered filesystem

Layered filesystem

Example: LXC, OpenVZ, BSD Jails

Example: Docker, Rocket

Diving into Docker

Docker is a container implementation that has gathered enormous interest in recent years. It neatly bundles various Linux kernel features and services such as namespaces, cgroups, SELlinux, AppArmor profiles, and so on, with Union file systems such as AUFS and BTRFS to make modular images. These images provide highly configurable virtualized environments for applications and follow the write-once-run-anywhere principle. An application can be as simple as running a process to having highly scalable and distributed processes working together.

Docker is gaining a lot of traction in the industry because of its performance savvy and universally replicable architecture, meanwhile providing the following four cornerstones of modern application development:

AutonomyDecentralizationParallelismIsolation

Furthermore, wide-scale adaptation of Thoughtworks's microservices architecture or Lots of Small Applications (LOSA) is further bringing potential to Docker technology. As a result, big companies such as Google, VMware, and Microsoft have already ported Docker to their infrastructure, and the momentum is continued with the launch of myriad of Docker start-ups namely Tutum, Flocker, Giantswarm, and so on.

Since Docker containers replicate their behavior anywhere, be it your development machine, a bare-metal server, virtual machine, or data center, application designers can focus their attention on development, while operational semantics are left to DevOps. This makes team workflow modular, efficient, and productive. Docker is not to be confused with VM, even though they are both virtualization technologies. Where Docker shares an OS, meanwhile providing a sufficient level of isolation and security to applications running in containers, it later completely abstracts out OS and gives strong isolation and security guarantees. But Docker's resource footprint is minuscule in comparison to VM, and hence preferred for economy and performance. However, it still cannot completely replace VM, and the usage of container is complementary to VM technology:

VM and Docker architecture

Advantages of Docker containers

Following are some of the advantages of using Docker containers in microservice architecture:

Rapid application deployment: With minimal runtime, containers can be deployed quickly because of the reduced size as only the application is packaged.Portability: An application with its operating environment (dependencies) can be bundled together into a single Docker container that is independent from the OS version or deployment model. The Docker containers can be easily transferred to another machine that runs Docker container and executed without any compatibility issues. Windows support is also going to be part of future Docker releases.Easily Shareable: Pre-built container images can be easily shared with the help of public repositories as well as hosted private repositories for internal use.Lightweight footprint: Even the Docker images are very small and have a minimal footprint to deploy a new application with the help of containers.Reusability: Successive versions of Docker containers can be easily built as well as rolled back to previous versions easily whenever required. It makes them noticeably lightweight as components from the pre-existing layers can be reused.

Docker lifecycle

These are some of the basic steps involved in the lifecycle of a Docker container:

Build the Docker image with the help of Dockerfile which contains all the commands required to be packaged. It can run in the following way:Docker build

Tag name can be added in following way:

Docker build -t username/my-imagename .

If Dockerfile exists at a different path then the Docker build command can be executed by providing -f flag:

Docker build -t username/my-imagename -f /path/DockerfileAfter the image creation, in order to deploy the container Docker run can be used. The running containers can be checked with the help of the Docker ps command, which lists the currently active containers. There are two more commands to be discussed:
Docker pause: This command uses cgroups freezer to suspend all the processes running in a container. Internally it uses the SIGSTOP signal. Using this command process can be easily suspended and resumed whenever required.Docker start: This command is used to start one or more stopped containers.
After the usage of container is done, it can either be stopped or killed; the Docker stop: command will gracefully stop the running container by sending the SIGTERM and then SIGKILL command. In this case, the container can still be listed by using Docker ps -a command. Docker kill will kill the running container by sending SIGKILL to the main process running inside the container.If there are some changes made to the container while it is running, which are likely to be preserved, a container can be converted back to an image by using the Docker commit after the container has been stopped:

The Docker lifecycle

Docker design patterns

Listed here are eight Docker design patterns with examples. Dockerfile is the base structure from which we define a Docker image, it contains all the commands to assemble an image. Using the Docker build command, we can create an automated build that executes all the preceding mentioned command-line instructions to create an image:

$ Docker buildSending build context to Docker daemon 6.51 MB...