XenonStack

A Stack Innovator

Post Top Ad

Tuesday 6 March 2018

Docker Overview - A Complete Guide

Blog Single Post Image

Docker Ecosystem

Docker is an open platform tool to make it easier to create, deploy and to execute the applications by using containers. Docker Containers allow us to separate the applications from the infrastructure so we can deploy application/software faster.
Docker have main components which includes Docker Swarm, Docker Compose, Docker Images, Docker Daemon, Docker Engine. 
We can manage our infrastructure in the same ways as we manage our applications. The Docker is like a virtual machine but creating a new whole virtual machine; it allows us to use the same Linux kernel.
The advantage of Docker platform is to ship, test, and deploy code quicker so that we can reduce the time between writing code and execute it in production.
And the main important thing about Docker is that its open source, i.e., anyone can use it and can contribute to Docker to make it easier and more features in it which aren’t available in it.

Docker Platform

The advantage of Docker is to build the package and run the application in sandbox environment said Container.
The docker container system utilizes the operating system virtualization to use and combine the components of an application system which support every standard Linux machine.
The isolation and security factors allow us to execute many containers parallel on a given system.
Containers are lightweight in size because they don’t need the extra resource of a HyperV or VMware, but run directly within the machine kernel. We can even run Docker containers within machines that are actually virtual/hyper machines.

Docker Container Components

The Core of the Docker consists of Docker Engine, Docker Containers, Docker images, Docker Client, Docker daemon, etc. Let discuss the components of the Docker.

Docker Engine

The Docker engine is a part of Docker which create and run the Docker containers. The docker container is a live running instance of a docker image. Docker Engine is a client-server based application with following components -
  • A server which is a continuously running service called a daemon process.
  • A REST API which interfaces the programs to use talk with the daemon and give instruct it what to do.
  • A command line interface client.
Docker Engine
The command line interface client uses the Docker REST API to interact with the Docker daemon through using CLI commands. Many other Docker applications also use the API and CLI. The daemon process creates and manage Docker images, containers, networks, and volumes.

Docker Daemon

The docker daemon process is used to control and manage the containers. The Docker daemon listens to only Docker API requests and handles Docker images, containers, networks, and volumes. It also communicates with other daemons to manage Docker services.

Docker Client

Docker client is the primary service using which Docker users communicate with the Docker. When we use commands “docker run” the client sends these commands to dockerd, which execute them out.
The command used by docker depend on Docker API. In Docker, client can interact with more than one daemon process.

Docker Images

The Docker images are building the block of docker or docker image is a read-only template with instructions to create a Docker container. Docker images are the most build part of docker life cycle.
Mostly, an image is based on another image, with some additional customization in the image.
We can build an image which is based on the centos image, which can install the Nginx web server with required application and configuration details which need to make the application run.
We can create our own images or only use those created by others and published in registry directory. To build our own image is very simple because we need to create a Dockerfile with some syntax contains the steps that needed to create the image and make to run it.
Each instruction in a Dockerfile creates a new layer in the image. If we need to modify the Dockerfile we can do the same and rebuild the image, the layers which have changed are rebuilt.
This is why images are so lightweight, small, and fast when compared to other virtualization technologies.

Docker Registries

A Docker registry keeps Docker images. We can run our private registry.
When we execute the docker pull and docker run commands, the required images are removed from our configured registry directory.
Using Docker push command, the image can be uploaded to our configured registry directory.

Docker Containers

A container is the instance of an image. We can create, run, stop, or delete a container using the Docker CLI. We can connect a container to more than one networks, or even create a new image based on its current state.
By default, a container is well isolated from other containers and its system machine. A container defined by its image or configuration options that we provide during to create or run it.

Namespaces

Docker using a service named namespaces is provided to the isolated environment called container. When we run a container, Docker creates a set of namespaces for that particular container. The namespaces provide a layer of isolation. Some of the namespace layer is -
  • Namespace PID provides isolation for the allocation of the process, lists of processes with details. In new namespace is isolated from other processes in its "parent" namespace still see all processes in child namespace
  • Namespace network isolates the network interface controllers, IP tables firewall rules, routing tables etc. Network namespaces can be connected with each other using the virtual Ethernet device.

Control Groups

Docker Engine in Linux relies on named control groups. A group limits the application to a predefined set of resources.
Control groups used by Docker Engine to share the available hardware resources to containers.
Using control groups, we can define the memory available to a particular container.

Union File Systems

Union file systems is a file system which is used by creating layers, making them lightweight and faster. Docker Engine using union file system provide the building blocks to containers.
Docker Engine uses many UnionFS variants some of including are AUFS, btrfs, vfs, Device Mapper, etc.

Container Format

Docker Engine adds the namespaces, control groups & UnionFS into a file called a container format. The default size for the container is lib container.

Docker File

docker file is a text file that consists of all commands so that user can call on the command line to build an image. Use of base Docker image add and copy files, run commands and expose the ports.
The docker file can be considered as the source code and images to make compile for our container which is running code. The Dockerfile are portable files which can be shared, stored and updated as required. Some of the docker files instruction is -
  • FROM - This is used for to set the base image for the instructions. It is very important to mention this in the first line of docker file.
  • MAINTAINER - This instruction is used to indicate the author of the docker file and its non-executable.
  • RUN - This instruction allows us to execute the command on top of the existing layer and create a new layer with the result of command execution.
  • CMD - This instruction doesn’t perform anything during the building of docker image. It Just specifies the commands that are used in the image.
  • LABEL - This Instruction is used to assign the metadata in the form key-value pairs. It is always best to use few LABEL instructions as possible.
  • EXPOSE - This instruction is used to listen on specific as required by application servers.
  • ENV - This instruction is used to set the environment variables in the Docker file for the container.
  • COPY - This instruction is used to copy the files and directory from specific folder to destination folder.
  • WORKDIR - This instruction is used to set the current working directory for the other instruction, i.e., RUN, CMD, COPY, etc.

Docker Architecture

Docker uses a client-server based architecture model. The Docker client communicates with the Docker daemon, which does process the lifting of the building, running, and distributing Docker containers.
We can connect a Docker client to another remote Docker daemon. The Docker client and daemon communicate using of REST API and network interface.
Docker Architecture

Key Features Of Docker

  • Docker allows us to faster assemble applications from components and eliminates the errors which can come when we shipping the code. For example, we can have two Docker containers running two different versions of the same app on the same system.
  • Docker helps us to test the code before we deploy it to production as soon as possible.
  • Docker is simple to use. We can get started with Docker on a minimal Linux, Mac, or Windows system running with compatible Linux kernel directly or in a Virtual Machine with a Docker binary.
  • We can "dockerize" our application in fewer hours. Mostly Docker containers can be launch with in a minute.
  • Docker containers run everywhere. We can deploy containers on desktops, physical servers, virtual machines, into data centers, and up to public and private clouds. And, we can run the same containers everywhere.

Docker Security

Docker security should be considered before deploy and run it. There are some areas which need to be considered while checking the Docker security which include security level of the kernel and how it support for namespaces and groups.
  • Docker daemon surface.
  • The container configuration file which can have loopholes by default or user has customized it.
  • The hardening security policy for the kernel and how it interacts with containers.

Overview of Docker Compose

Docker Compose is a tool which is used to define and running multiple-containers in Docker applications. Docker composes use to create a compose file to configure the application services. After that, a single command, we set up and start all the services from our configuration.
Docker Compose is a beneficial tool for development, testing, and staging environments.
Docker Compose is a three-step process.
  • Define the app’s environment with a Dockerfile so that it can be reproduced anytime and anywhere.
  • Define the services in docker-compose.yml after that we can be run together in an isolated environment.
  • After that, using docker-compose up and Compose will start and execute the app.

Features of Docker Compose

The features of docker compose that make it unique are -
  • Multiple isolated environments can be run on a single host
  • Store volume data when containers are created
  • Only recreate containers in which configurations have been changed.

Getting Started With Swarm Mode

Docker Engine version also includes swarm mode for managing a cluster of Docker Engines said a swarm. With the help of Docker CLI, we create a swarm, deploy application services to a swarm, and manage swarm.

Features of Swarm Mode

  • Cluster management integrated with Docker Engine - Using the Docker Engine CLI we create a swarm of Docker Engines where we can easily deploy application services. We don’t need any additional software to create or manage a swarm.
  • Decentralized design - We can deploy any kinds of node, manager, and worker, using the Docker Engine. It means we can build an entire swarm from a single disk image.
  • Service model - Docker Engine uses a declarative approach so that we can define the desired state of the various services in our application stack.
  • Scaling - For every service, declare the number of tasks we want to run. When we scale up or down, the swarm manager automatically does the changes by add or remove functions to maintain the required state.
  • MultiSystem Networking - We can use an overlay network for the services or applications. Swarm manager assigns addresses to the containers on the overlay network when it starts the application.
  • Discovery Service - Swarm manager nodes assign each service in the swarm a DNS name and load balance running containers. We can query any container running in the swarm through a DNS server in the swarm.
  • Load balancing - We can expose the ports for services to an external load balancer. In Internal, using swarm, we can decide how to distribute service containers between nodes or hosts.
  • TLS Certificate - Each node in the swarm mode enforces to use TLS authentication & encryption to secure communications with all other nodes. We have the option to use self-signed root certificates or certificates from a custom root CA.
  • Rolling updates in Docker - We can apply service updates to nodes incrementally. The swarm manager controls the delay between service deployment to different sets of hosts. If something goes wrong, we can roll-back a task to a previous version of the service.

Continue Reading:XenonStack/Blog

No comments:

Post a Comment