The Wayback Machine - https://web.archive.org/web/20241013191100/https://www.geeksforgeeks.org/containerization-using-docker/
Open In App

Containerization using Docker

Last Updated : 11 Jul, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Docker is the containerization platform that is used to package your application and all its dependencies together in the form of containers to make sure that your application works seamlessly in any environment which can be developed or tested or in production. Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. 
 

Docker is the world’s leading software container platform. It was launched in 2013 by a company called Dotcloud, Inc which was later renamed Docker, Inc. It is written in the Go language. It has been just six years since Docker was launched yet communities have already shifted to it from VMs. Docker is designed to benefit both developers and system administrators making it a part of many DevOps toolchains. Developers can write code without worrying about the testing and production environment. Sysadmins need not worry about infrastructure as Docker can easily scale up and scale down the number of systems. Docker comes into play at the deployment stage of the software development cycle. 
 

 

Containerization 

Containerization is OS-based virtualization that creates multiple virtual units in the userspace, known as Containers. Containers share the same host kernel but are isolated from each other through private namespaces and resource control mechanisms at the OS level. Container-based Virtualization provides a different level of abstraction in terms of virtualization and isolation when compared with hypervisors. Hypervisors use a lot of hardware which results in overhead in terms of virtualizing hardware and virtual device drivers. A full operating system (e.g -Linux, Windows) runs on top of this virtualized hardware in each virtual machine instance. 
But in contrast, containers implement isolation of processes at the operating system level, thus avoiding such overhead. These containers run on top of the same shared operating system kernel of the underlying host machine and one or more processes can be run within each container. In containers you don’t have to pre-allocate any RAM, it is allocated dynamically during the creation of containers while in VMs you need to first pre-allocate the memory and then create the virtual machine. Containerization has better resource utilization compared to VMs and a short boot-up process. It is the next evolution in virtualization. 

Containers can run virtually anywhere, greatly easy development and deployment: on Linux, Windows, and Mac operating systems; on virtual machines or bare metal, on a developer’s machine or in data centers on-premises; and of course, in the public cloud. Containers virtualize CPU, memory, storage, and network resources at the OS level, providing developers with a sandboxed view of the OS logically isolated from other applications. Docker is the most popular open-source container format available and is supported on Google Cloud Platform and by Google Kubernetes Engine. 

 

 

Docker Architecture

Docker architecture consists of Docker client, Docker Daemon running on Docker Host, and Docker Hub repository. Docker has client-server architecture in which the client communicates with the Docker Daemon running on the Docker Host using a combination of REST APIs, Socket IO, and TCP. If we have to build the Docker image, then we use the client to execute the build command to Docker Daemon then Docker Daemon builds an image based on given inputs and saves it into the Docker registry. If you don’t want to create an image then just execute the pull command from the client and then Docker Daemon will pull the image from the Docker Hub finally if we want to run the image then execute the run command from the client which will create the container. 

 

 

Components of Docker

The main components of Docker include – Docker clients and servers, Docker images, Dockerfile, Docker Registries, and Docker containers. These components are explained in detail in the below section : 
 

  1. Docker Clients and Servers– Docker has a client-server architecture. The Docker Daemon/Server consists of all containers. The Docker Daemon/Server receives the request from the Docker client through CLI or REST APIs and thus processes the request accordingly. Docker client and Daemon can be present on the same host or different host. 
     

  1. Docker Images– Docker images are used to build docker containers by using a read-only template. The foundation of every image is a base image eg. base images such as – ubuntu14.04 LTS, and Fedora 20. Base images can also be created from scratch and then required applications can be added to the base image by modifying it thus this process of creating a new image is called “committing the change”.
  2. Docker File– Dockerfile is a text file that contains a series of instructions on how to build your Docker image. This image contains all the project code and its dependencies. The same Docker image can be used to spin ‘n’ number of containers each with modification to the underlying image. The final image can be uploaded to Docker Hub and shared among various collaborators for testing and deployment. The set of commands that you need to use in your Docker File is FROM, CMD, ENTRYPOINT, VOLUME, ENV, and many more.
  3. Docker Registries– Docker Registry is a storage component for Docker images. We can store the images in either public/private repositories so that multiple users can collaborate in building the application. Docker Hub is Docker’s cloud repository. Docker Hub is called a public registry where everyone can pull available images and push their images without creating an image from scratch.
  4. Docker Containers– Docker Containers are runtime instances of Docker images. Containers contain the whole kit required for an application, so the application can be run in an isolated way. For eg.- Suppose there is an image of Ubuntu OS with NGINX SERVER when this image is run with the docker run command, then a container will be created and NGINX SERVER will be running on Ubuntu OS. 

     

 

Docker Compose

Docker Compose is a tool with which we can create a multi-container application. It makes it easier to configure and 
run applications made up of multiple containers. For example, suppose you had an application that required WordPress and MySQL, you could create one file which would start both the containers as a service without the need to start each one separately. We define a multi-container application in a YAML file. With the docker-compose-up command, we can start the application in the foreground. Docker-compose will look for the docker-compose. YAML file in the current folder to start the application. By adding the -d option to the docker-compose-up command, we can start the application in the background. Creating a docker-compose. YAML file for WordPress application : 

 

#cat docker-compose.yaml
version: ’2’
services:
db:
image: mysql:5.7
volumes:db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: WordPress
MYSQL_DATABASE: WordPress
MYSQL_USER: WordPress
MYSQL_PASSWORD: WordPress
WordPress:
depends_on:
- DB
image: WordPress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306

WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:

In this docker-compose. YAML file, we have the following ports section for the WordPress container, which means that we are going to map the host’s 8000 port with the container’s 80 port. So that host can access the application with its IP and port no. 

 

Docker Networks

When we create and run a container, Docker by itself assigns an IP address to it, by default. Most of the time, it is required to create and deploy Docker networks as per our needs. So, Docker let us design the network as per our requirements. There are three types of Docker networks- default networks, user-defined networks, and overlay networks. 
 

To get a list of all the default networks that Docker creates, we run the command shown below – 
 

There are three types of networks in Docker – 
 

  1. Bridged network: When a new Docker container is created without the –network argument, Docker by default connects the container with the bridge network. In bridged networks, all the containers in a single host can connect through their IP addresses. A Bridge network is created when the span of Docker hosts is one i.e. when all containers run on a single host. We need an overlay network to create a network that has a span of more than one Docker host.
  2. Host network: When a new Docker container is created with the –network=host argument it pushes the container into the host network stack where the Docker daemon is running. All interfaces of the host are accessible from the container which is assigned to the host network.
  3. None network: When a new Docker container is created with the –network=none argument it puts the Docker container in its network stack. So, in this none network, no IP addresses are assigned to the container, because of which they cannot communicate with each other.

We can assign any one of the networks to the Docker containers. The –network option of the ‘docker run’ command is used to assign a specific network to the container. 
 

$docker run --network ="network name"

To get detailed information about a particular network we use the command- 
 

$docker network inspect "network name"

 

Advantages of Docker –

Docker has become popular nowadays because of the benefits provided by Docker containers. The main advantages of Docker are: 
 

  1. Speed – The speed of Docker containers compared to a virtual machine is very fast. The time required to build a container is very fast because they are tiny and lightweight. Development, testing, and deployment can be done faster as containers are small. Containers can be pushed for testing once they have been built and then from there on to the production environment.
  2. Portability – The applications that are built inside docker containers are extremely portable. These portable applications can easily be moved anywhere as a single element and their performance also remains the same.
  3. Scalability – Docker has the ability that it can be deployed on several physical servers, data servers, and cloud platforms. It can also be run on every Linux machine. Containers can easily be moved from a cloud environment to a local host and from there back to the cloud again at a fast pace.
  4. Density – Docker uses the resources that are available more efficiently because it does not use a hypervisor. This is the reason that more containers can be run on a single host as compared to virtual machines. Docker Containers have higher performance because of their high density and no overhead wastage of resources.

 



Previous Article
Next Article

Similar Reads

Implementation of CI/CD in Java application(Linux) Using Shell and Docker Executor on GitLab
There are many executors available to implement CI/CD with GitLab Runner. However, Shell and Docker are more popular among them, and we can easily configure a repository with these runners. These runners can be chosen based on the requirements and availability of the resources. This article mainly focuses on Shell and Docker executors of Java Linux
6 min read
Load Balancing Flask Application using Nginx and Docker
Load balancing means efficiently distributing the incoming traffic to different server instances. Nginx is open-source software that can be used to apply load balancing to backend systems. Nginx also can be serve services such as reverse proxy, caching, web server, etc. Docker is a tool that gives a virtualization solution for a complete software p
5 min read
Install GitLab By Using Docker
GitLab is a popular DevOps platform that provides a complete suite of tools for managing your software development lifecycle. It includes features like version control, CI/CD pipelines, and project management, making it an important tool for many development teams. In this article, we will walk you through the steps to install GitLab using Docker.
3 min read
Installing Helm & Kubernetes in Docker
Helm is simply a package manager for Kubernetes. It helps you manage Kubernetes applications — Helm Charts helps you define, install, and upgrade even the most complex Kubernetes application. Implementation: Follow the below steps to install Helm and Kubernetes in Docker: Step 1: Installing Docker First, download the Docker.exe from the official si
2 min read
Why Should You Use Docker - 7 Major Reasons!
Containerization is a technology that is enjoying huge popularity in the tech world - and Docker is a renowned player of it. You need to know that numerous IT giants are providing various enriching career opportunities to Docker professionals. The major reason behind such an immensely growing demand for Docker is that it actually resolves the cult
7 min read
How to install and configure Docker on Godaddy server?
In this article, we will discuss how to install the latest version of Docker on GoDaddy VPS (Ubuntu). Installing Docker on Godaddy Server Step 1: Open your terminal and ssh into the GoDaddy Server. $ ssh [username]@[ip] Step 2: Update and upgrade the server by running. $ sudo apt update -y $ sudo apt upgrade -y Step 3: Now install the latest versio
1 min read
Use of Docker Playground
Pre-requisite: Docker Play with Docker or Docker Playground is a simple, interactive, and fun playground to learn Docker. It is an open-source platform for building, shipping, and running applications on containers online for learning or testing purposes online. This service is offered by Docker Inc and is free to use for all users for learning pur
2 min read
Top 10 Docker Alternatives For Software Developers
Imagine you worked hard to create an application with various libraries and dependencies. The application runs smoothly and efficiently on your system. What if want to send the application to someone else’s system? The person would require a whole lot of setup of the application to run it. Even after the setup, a single change in the code and confi
11 min read
10 Best Docker Projects with Source Code
Docker is a type of containerization software or a PaaS tool that allows the user to fragment applications and their environment into small chunks which can be stored and deployed in any machine. Basically, Docker is used as a powerful tool to manage and deploy the applications efficiently by the developers. With the help of containerization, diffe
8 min read
Top 10 Docker Projects Ideas for Beginners [2024]
Docker is a revolutionary tool used in the software world for developing, packaging, deploying, and managing applications efficiently. It is going to become the most demanding technology in 2024 and having projects of docker in skill bank is more valuable for developers. This article will provide you with the Top 10 Docker Project Ideas in 2024 tha
9 min read
Top 10 Docker Container That Every Developer Should Know
In the technical field, each and every developer has heard about Docker and Docker containers. Docker is mainly a tool that is used for shipping and running applications and it also uses OS-level virtualization to deliver this software in packages which are called containers. One of the most common problems of the developers is they don’t have an i
7 min read
Virtualisation with Docker Containers
In a software-driven world where omnipresence and ease of deployment with minimum overheads are the major requirements, the cloud promptly takes its place in every picture. Containers are creating their mark in this vast expanse of cloud space with the world’s top technology and IT establishments relying on the concept for their infrastructural nec
9 min read
How to Set up Docker and NGINX for a Next.js?
In the world of microservices, it is necessary to containerize our applications for deployments. It makes life easier for developers, allowing them to build and test applications in a controlled environment. Containers provide isolation, meaning that each instance runs independently of others, preventing conflicts between dependencies and ensuring
3 min read
How to Call 'npm start' though Docker ?
Docker is a powerful tool for creating, deploying, and running applications inside containers. If you have a Node.js application, you might want to run it inside a Docker container to ensure consistency across different environments. This article will guide you on how to call npm start through Docker to run your Node.js application. It runs the app
2 min read
Next.js Docker Images
Using Next.js Docker Images ensures consistent deployment across various environments. It enhances portability, isolation, and scalability for both development and production. Leveraging Docker's containerization provides seamless application management and reliable performance across different stages. What Is Docker Image?A Docker image is a read-
5 min read
What is Docker?
Docker is a set of Platforms as a service (PaaS) products that use Operating system-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels. All containers are
15+ min read
How to Use Docker for Web Development
Docker has become a necessary tool for web developers, especially due to the fluid nature of managing and deploying applications. Docker containerizes an application with all its dependencies required to run the application, which makes it consistent across different environments. Doing this will make it easier to develop, test, and deploy your app
8 min read
Top 10 Docker Commands You Need to Know
Docker has changed the goalposts of application development and deployment by providing a standard environment to run the applications, which is independent of their place of deployment. Moving forward into 2024, as a developer and DevOps engineer, one has to fully understand and know how to use appropriately the basic Docker commands. This article
7 min read
How to use React or Vue with Vite and Docker?
This guide will provide details on how to create a Docker container with a new React project integrated with Vite. When combined, with Vite’s short build times and Docker’s ability to create a consistent and reproducible environment, you can quickly achieve developmental parity with the production environment. This also makes it easy to deploy your
3 min read
Kubernetes vs Docker
In the world of containerization both the tools server as vital tools with respective their features. Docker is a platform for containerization, while Kubernetes manages containers for numerous container runtimes. There is various container runtimes supported by Kubernetes, some of those are as follows: DockerContainersCRI-OMirantis Container Runti
11 min read
How to find record using any key-value pair information of record in your local/custom database using Node.js ?
The custom database signifies the local database in your file system. There are two types of database ‘SQL’ and ‘NoSQL’. In SQL database data are stored as table manner and in Nosql database data are stored independently with some particular way to identify each record independently. We can also create our own database or datastore locally in Nosql
5 min read
Largest Rectangle Area under Histogram using JavaScript | Without using Stacks
Find the largest rectangular area possible in a given histogram where the largest rectangle can be made of a number of contiguous bars. For simplicity, assume that all bars have the same width and the width is 1 unit. For example, consider the following histogram with 7 bars of heights {6, 2, 5, 4, 5, 1, 6}. The largest possible rectangle possible
2 min read
Build an E-Commerce Web Application using HTML CSS PHP and hosted using XAMPP
In this article, we will see know how to develop a simple e-commerce Web application that offers a seamless and user-friendly experience for customers, allowing them to register and login into their accounts,  easily browse for products, add items to their cart, and also allow them to add their delivery address, with the help of HTML, CSS & PHP
11 min read
How to submit a form without using submit button using PHP ?
In this article, we will see how to submit the form without clicking the submit button, along with understanding the different ways to accomplish this task through implementation. The form can be submitted without using submit button by implementing a specific event attribute or by clicking the link. This task can be done by using the OnClick event
3 min read
How to make a website using WordPress (Part - 1)
Hi guys, most of us at some instances of time face a problem with how to start something for a minor or major project. Many of us wish to make a website-based project but do not know how to proceed. To assist all my friends, today I'll walk you through the process of installing and getting acquainted with the WordPress environment. Below I give ste
3 min read
How to make a JSON call using jQuery ?
Use the getJSON() function in jQuery to load JSON data. The getJSON() function uses a GET HTTP request to retrieve JSON-encoded data from the server. In this article, we will learn about the jQuery getJSON() function and its implementation through examples. Syntax: $(selector).getJSON(url, data, success(data, status, xhr)) Parameters: This method a
3 min read
How to create a Fieldcontain mini sized using jQuery Mobile ?
jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating a Fieldcontain mini sized using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. <link rel=”stylesheet” href=”http://code.jquery.com/mobile/1.4.5/jq
1 min read
How to change cursor color using CSS ?
In this article, we will see how to change the cursor color in the input fields using CSS. To change the cursor color, we will use caret-color property. This property is used to set the color of the cursor for input fields, textarea, or other editable areas. Syntax: caret-color: auto|color; Parameters: auto: It has a default value. It uses the curr
2 min read
How to make a Mini sized vertical controlgroups using jQuery Mobile ?
jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be making a Mini sized vertical controlgroups using jQuery Mobile. Approach: First, add jQuery Mobile scripts needed for your project. <link rel="stylesheet" href="http://code.jquery.com/
2 min read
Round off a number upto 2 decimal place using JavaScript
A number can be rounded off to 2 decimal places using 2 approaches: Method 1: Using the toFixed() method: The toFixed() method is used to return a string representation of a number up to a certain number of digits after the decimal point. The number is rounded and the fractional part is padded if necessary to make it the specified length. It takes
2 min read
Article Tags :