DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • 7 Ways of Containerizing Your Node.js Application
  • Auto-Scaling a Spring Boot Native App With Nomad
  • Manage Microservices With Docker Compose
  • Request Routing Through Service Mesh for WebSphere Liberty Profile Container on Kubernetes

Trending

  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 1
  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  • Building Enterprise-Ready Landing Zones: Beyond the Initial Setup
  • Integration Isn’t a Task — It’s an Architectural Discipline
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Docker Explained – An Introductory Guide to Docker

Docker Explained – An Introductory Guide to Docker

Welcome to the wide world of Docker.

By 
Sahiti Kappagantula user avatar
Sahiti Kappagantula
·
Oct. 29, 19 · Tutorial
Likes (19)
Comment
Save
Tweet
Share
38.1K Views

Join the DZone community and get the full member experience.

Join For Free

Docker has gained immense popularity in this fast-growing IT world. Organizations are continuously adopting Docker in their production environment. I take this opportunity to explain Docker in the most simple way. In this blog, the following Docker concepts will be covered:

  • History Before Containerization
  • Reasons to use containers
  • What is Docker?
  • Dockerfile, Images, and Containers
  • Docker Compose and Docker Swarm
  • Hands-On

Since Docker is a containerization platform before I tell you about it, it’s important that you understand the history behind containerization.

Docker Explained: History Before Containerization 

Before containerization came into the picture, the leading way to isolate, organize applications and their dependencies was to place each and every application in its own virtual machine. These machines run multiple applications on the same physical hardware, and this process is nothing but Virtualization.

But virtualization had few drawbacks, including that virtual machines were bulky in size, running multiple virtual machines lead to unstable performance, the boot-up process would usually take a long time and VM’s would not solve the problems like portability, software updates, or continuous integration and continuous delivery.

These drawbacks led to the emergence of a new technique called containerization.

Containerization

Containerization is a type of virtualization which brings virtualization to the operating system level. While virtualization brings abstraction to the hardware, containerization brings abstraction to the operating system.

Moving ahead, it’s the time that you understand the reasons to use containers.

Reasons to Use Containers

Here are the reasons to use containers:

  • Containers have no guest OS and use the host’s operating system. So, they share relevant libraries and resources as and when needed.
  • Processing and execution of applications are very fast since applications specific binaries and libraries of containers run on the host kernel.
  • Booting up a container takes only a fraction of a second, and also containers are lightweight and faster than Virtual Machines.

Now, that you have understood what containerization is and the reasons to use containers, it’s the time you understand What is Docker?

Docker Explained: What Is Docker?

Docker is a platform that packages an application and all its dependencies together in the form of containers. This containerization aspect of Docker ensures that the application works in any environment.

Containerization

Containerization


As you can see in the diagram, each and every application runs on separate containers and has its own set of dependencies and libraries. This makes sure that each application is independent of other applications, giving developers reassurance that they can build applications that will not interfere with one another.

So a developer can build a container having different applications installed on it and give it to the QA team. Then the QA team would only need to run the container to replicate the developer’s environment.

Dockerfile, Images, and Containers

Dockerfile, Docker images, and Docker containers are three important terms that you need to understand while using Docker.

Dockerfile, Images and Containers

Dockerfile, Images and Containers


As you can see in the above diagram when the Dockerfile is built, it becomes a Docker image, and when we run the Docker image then it finally becomes a Docker container.

  • Dockerfile: A Dockerfile is a text document that contains all the commands that a user can call on the command line to assemble an image. So, Docker can build images automatically by reading the instructions from a Dockerfile. You can use docker build to create an automated build to execute several command-line instructions in succession.

  • Docker Image: In layman's terms, a Docker image can be compared to a template that is used to create Docker containers. So, these read-only templates are the building blocks of a Docker container. You can use docker run to run the image and create a container. Docker images are stored in the Docker Registry. It can be either a user’s local repository or a public repository like a Dockerhub which allows multiple users to collaborate in building an application.

  • Docker Container: Docker container is a running instance of a Docker image as they hold the entire package needed to run the application. So, these are basically the ready applications created from Docker images, which is the ultimate utility of Docker.

Docker Explained: Docker Compose and Docker Swarm

Docker Compose is a YAML file that contains details about the services, networks, and volumes for setting up the Docker application. So, you can use Docker Compose to create separate containers, host them, and get them to communicate with each other. Each container will expose a port for communicating with other containers.

Docker Swarm is a technique to create and maintain a cluster of Docker engines. The Docker engines can be hosted on different nodes, and these nodes, which are in remote locations, form a cluster when connected in swarm mode.

With this, we come to an end to the theory part of this Docker Explained blog, wherein you must have understood all the basic terminologies.

Docker Explained: Hands-On

Follow the below steps to create a Dockerfile, image, and container.

Step 1: First you have to install Docker. 

Step 2: Once Docker is installed, use the below command to check the Docker version.

docker -v


Snapshot Of Demo - Docker Explained - Edureka


Step 3: Now create a folder in which you can create a Dockerfile and change the current working directory to that folder.

mkdir images
cd images

Snapshot Of Demo - Docker Explained - Edureka


Step 4.1: Now create a Dockerfile by using an editor. In this case, I have used the nano editor.

nano Dockerfile

Snapshot Of Demo - Docker Explained - Edureka


Step 4.2: After you open a Dockerfile, you have to write the Dockerfile as follows.

FROM ubuntu:latest
MAINTAINER Sahiti (email@domain.com)
RUN apt-get update
RUN apt-get install -y nginx
ENTRYPOINT ["/usr/sbin/nginx","-g","daemon off;"]
EXPOSE 80

Snapshot Of Demo - Docker Explained - Edureka


  •  FROM: Specifies the image that has to be downloaded
  •  MAINTAINER: Metadata of the owner who owns the image
  •  RUN: Specifies the commands to be executed
  •  ENTRYPOINT: Specifies the command which will be executed first
  •  EXPOSE: Specifies the port on which the container is exposed

Step 4.3: Once you are done with that, just save the file.

Step 5: Build the Dockerfile using the below command.

docker build

** “.” is used to build the Dockerfile in the present folder **

Snapshot Of Demo - Docker Explained - Edureka

Step 6: Once the above command has been executed the respective Docker image will be created. To check whether Docker Image is created or not, use the following command.

docker images

Snapshot Of Demo - Docker Explained - Edureka



Step 7: Now to create a container based on this image, you have to run the following command:

docker run -it -p port_number -d image_id

Where  -it is to make sure the container is interactive,  -p  is for port forwarding, and  -d to run the daemon in the background.

Snapshot Of Demo - Docker Explained - Edureka

Step 8: Now you can check the created container by using the following command:

docker ps

Snapshot Of Demo - Docker Explained - Edureka

With this we come to the end of this article, I hope you enjoyed this blog.

Further Reading

Understanding Dockerfile

Kubernetes vs. Docker

Docker (software) Kubernetes application

Published at DZone with permission of Sahiti Kappagantula, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • 7 Ways of Containerizing Your Node.js Application
  • Auto-Scaling a Spring Boot Native App With Nomad
  • Manage Microservices With Docker Compose
  • Request Routing Through Service Mesh for WebSphere Liberty Profile Container on Kubernetes

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!