Dark Mode
  • Tuesday, 16 April 2024
DevOps-8: Containerization [Docker]

DevOps-8: Containerization [Docker]

DevOps-8: Containerization [Docker] - Outline

8.1. Learning Objectives

Developer can use containerization technology to create and deploy apps more quickly and securely. Containerization allows developers to write code in one place that can be executed anywhere.

Docker – is the most well-known containerization tool.


Docker provides the following features:

  • Docker Networking
  • Network driver
  • Docker Compose
  • Docker Registry



8.2. Overview of Containerization

Containerization allows developers in your organization to construct and deploy apps faster and more securely. Container technology is extremely useful in today’s business world where applications must be platform-independent. Containerization plays a pivotal role in the deployment process,


Container: A Container is a piece of software that packages code and all of its dependencies.


Containerization is the process of packaging software code along with all of its essential components.


Benefits of Containerization:

  • Portability: A container separates application from their host operating system, making them portable.
  • Scalability: A container application can withstand rising workloads by using a service-oriented application design.
  • Faster Development: A container can create a master version of an image that can be distributed on demand, increasing app productivity.
  • High Productivity: Container allow developers to track and make changes to the platform’s source code.
  • Enhanced Security: Containerization increases security by adhering to an app separation mechanism.
  • Continuity: Containerization ensures continuity because containers operate independently.


8.3. Containerization vs. Virtualization

Virtualization allows you to run different operation systems on the same physical server’s hardware.


These are two most common methods for hosting application on a computer system.



Docker Docker


8.4. Docker Overview

Docker is a containerization platform for packaging your application along with all of its dependencies.


Docker is a free and open platform for developing, deploying, and running software.


Docker platform is a feature provided by Docker to manage the lifecycle of containers.


User of the Docker platform:


Whether your production environment is:

  • Data Center
  • Cloud Provider
  • Hybrid Cloud

Advantages of Docker: Some of the benefits Docker delivers at various stages of the software development lifecycle (SDLC) are as below,

  • Build
  • Test
  • Deploy
  • Maintain

Features: Features provided by Docker:

  • Scalable
  • Provides easy and faster configuration
  • Is able to reduce the size
  • Increases productivity
  • Reduces infrastructure and maintenance costs.
  • Application Isolation
  • Swarm
  • Routing mesh
  • Services
  • Security Management


8.5. Docker Components

Docker Architecture: Docker uses a client-server architecture.


There are few key components of the Docker architecture,

  1. Docker Host:
  2. Docker Client:
  3. Docker Registries:
  4. Docker Object:

Different types of Docker Objects:

  1. Image: Read-only template
  2. Container: Generate when you run an image
  3. Volume: Used to store persistent data
  4. Network: A way for all the isolated containers to communicate with one another.


Docker Engine: Docker engine is the core part of a Docker system. It is an application with a client-server architecture that is installed on the host machine.



8.6. Docker Installation

System requirement to install Docker is:

  • Disco 19.4
  • Cosmic 18.10
  • Bionic 18.04(LTS)
  • Xenial 16.04(LTS)


  1. Download package information from all configuration sources

    $ sudo apt-get update
  2. The following command install the packages that enable apt to use an HTTPS repository:

    $ sudo apt-get install \
    $ apt-transport-http \
    $ ca-certificates \
    $ curl \
    $ gnupg \
    $ isb-release
  3. Use the following curl command to add Docker’s official GPG key:

    $ curl-fsSL http://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpgz
  4. Set up a stable repository using the command,

    $ echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] http://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list> /dev/null
  5. Download package information from all configuration sources

    $ sudo apt-get update
  6. This command installs the most recent version of Docker CE

    $ sudo apt-get install docker-ce
  7. To check the docker version,

    $ docker –version
  8. Verify the currently installed Docker engine by using the command below,

    $ sudo docker run hello-world


8.7. Docker Image and Containers

An image is a read-only template for building a Docker container.


Users can use a Docker file to create and use their image by following a simple syntax for defining the steps required.


Docker images are lightweight, tiny and fast



Types of Docker image:

  1. Parent Image:
    • It is specified by the FROM directive in the image’s Docker-file
    • It serves as the foundation for all the docker commands
    • A Docker file’s FROM scratch directive creates a basic image without using any parent images.
  2. Base Image:
    • It doesn’t have a parent image in its Docker-file
    • A FROM scratch directive is used in a Docker-file to create it.


Some basic Docker image commands:

Docker Docker Docker


Docker Container: A container is a runnable image instance. A container is isolated form other containers and its host machine. A user define container by its image and any configuration options provide while creating or starting it. It is a tool create, test and deploy an application.



Docker API and CLI helps in:



A user can:

Docker Docker


8.8. Docker Networking

Networking allows Docker containers to communicate between Host and Client machine.

Docker’s networking subsystem is pluggable and driver-based. Default Network drivers provided by Docker are:


  1. Bridge: It uses a software bridge to achieve connectivity and prevents containers from direct communication by implementing rules on the host machine. Docker
  2. Host: It is ideal to connect the containers which share the host’s networking namespace. Docker
  3. Overlay: It allow two standalone containers (including swarm service) on different Docker demons to connect. Docker
  4. Macvlan: It is ideal for legacy application or network traffic monitoring apps that demand to be connected directly to the physical network. Docker
  5. None: It is used to completely disable the networking stack on a container. Docker


Network Driver: Third-party network plugins can be used to integrate Docker with specialized network stacks.

  1. Bridge: When multiple containers need to communicate on the same Docker host.
  2. Host: When the network stack should not be isolated form the Docker host, but other components of the container should be host network.
  3. Overlay: When containers running of different Docker hosts need to communicated, or when multiple apps require swarm service.
  4. Macvlan: When container is required to look like physical hosts on the network, each with its own MAC address.


8.9. Docker Registry and Docker Hub

It is a storage and distribution system for named Docker images. Docker users can pull images locally and push new images to the Registry.


The Docker Registry is compatible with Docker engine version 1.6.0 or higher. A user should use the Registry if they want to:



Docker Hub: The world’s largest container image library and community. A user can utilize Docker Hub to search and share container images with their team. A user can browse over 100,000 container images from:

  • Software manufactures/li>
  • Open-Source Project
  • Community

Features of Docker Hub:



Docker Hub allows you to:

  • Explore the world’s largest container image repository
  • Easy search over million container images
  • Share and store images in public or private repository
  • Access free public repository or select a subscription plan for private repository
  • Become a verified publisher
  • Run more technology in containers with certified infrastructure, container and plugins.


8.10. Docker Compose Overview

Docker compose is a tool that allows users to define and run multi-container Docker applications.


All the services in your configuration can eb created and started with single command.


Docker composer is compatible with the following environments:



Three-step process of using Compose:

  • Create a Dockerfile
  • Define the service in docker-compose.yml
  • Run Docker compose up or docker-compose up command


A sample docker-compose.yml file:



Features of Docker Compose:



Docker Compose use cases:



Some fundamental Docker Compose Commands:

Docker Docker Docker Docker


8.11. Demo - Push a Docker Image on Docker Hub


app.py file is below,



~/pythonapp$ nano requirements.txt


~/pythonapp$ nano Dockerfile

Docker Docker Docker Docker Docker


Go to http://hub.docker.com

Docker Docker


Login to your http://hub.docker.com

Docker Docker Docker

Those we have successfully pushed an image to Docker Hub.


8.12. Quick Recap

Containerization is a method for developers to build and deploy applications more rapidly and securely, ensuring bug-free portability of the application. The developer team containerizes the legacy application.


Docker image will help the developers in creating a new application with a slight configuration change. Macvlan network driver can be used to connect the application directly to the physical network.




Comment / Reply From