We often hear the word docker in our work places, but there still remains a lack of understanding among many individuals regarding its precise definition. Now, let’s dive into the Docker concept, including its definition, significance, and the benefits it offers over other hosting methods such as on-premises and virtual machines.
What is a Docker?
Docker is a software platform designed for efficient development, testing, and deployment of applications. It utilizes standardized units known as containers to package software with all necessary components for running, such as libraries, system tools, code, and runtime. With Docker, applications can be easily and rapidly deployed and scaled across various environments, ensuring seamless execution of code.
Different Ways of Hosting an Application
On-premises/Dedicated Machine
Utilizing resources such as Compute, Power, Networking, Maintenance, and Security can be challenging due to high costs and complexity in management and maintenance.
Virtualization
It’s a method of making multiple counter parts of a hardware to create many isolated environments on a single host machine based on its capacity. With this method, we can utilize the resources more efficiently than on-premises. But the VM takes a long time to restart, and it requires memory for each OS separately.
Containerization
It is the way of building, running, and shipping software packages in light weighted containers. Using this method, we can effectively utilize the compute resources. It consumes less memory, and provides more flexibility than other platforms.
Docker
Developers widely use this containerization tool to quickly and effectively build, run, and ship applications. Docker hosts these applications, ensuring they remain lightweight by consuming only the necessary compute resources. Additionally, Docker avoids unnecessary utilization of guest operating systems or other resources that are not relevant to the application or its deployment.
Application Hosting using Docker
When we are ready with the source code, then we need to instruct the docker where to execute, what to execute, how to execute. For this, we must create a text file like read-only template called “Image” with all the steps needed from executing the code to deploying the application.
After successful creation of an image, we have to instruct docker to allocate an isolated portion of Hardware, CPU, Memory, and Storage to create a runtime instance of the application.
Building
This involves running the source code with the necessary runtime and version to generate an image.
Shipping
If an image is successfully built on a machine, it can be used to host/deploy in other machine to run the application.
Docker Concepts
Dockerfile : It has a set of instructions to build a Docker image
Docker Image : Docker Image is a set of read-only files that are combined into a package in order to run a software application. An image is build layer by layer containing the data instructed in each line of Dockerfile.
Docker Container: A container is a program that operates with its own isolated hardware resources, running a runtime instance of a docker image.
Docker Daemon : It serves as the backend for the docker service, generating and managing docker objects such as Images, Containers, Volumes, etc. through host communication
Docker CLI: By sending docker commands to the docker daemon, users can interact with it via Docker CLI.
REST APIs : REST APIs are used for communication between the Docker CLI and the Docker Daemon.
Docker Registry : It’s a place where we can find and pull the docker images for free in our Docker files as per the requirements. Example: Docker Hub
Basic Dockerfile to Host a Nginx Web Server
FROM nginx
EXPOSE 80
CMD [“nginx”,”-g”,”daemon off;”]
Build this Dockerfile to get an Image
$ docker build –t nginx .
Run the container from the image
$ docker run –it --name nginx-server –p 80:80 nginx
Access the Nginx Server on browser
http://localhost:80 or http://<Public-IP of the server>:80
You should be able to see the page like the below image
Benefits of Docker
- Provisioning of containers are much faster than VMs
- Containers have the ability to start within seconds, as opposed to virtual machines which can take several minutes to launch.
- Docker utilizes the kernel of the Host OS and includes essential binaries and libraries as needed
- Effective utilization of compute resources
- Consumes minimal storage when compared to VMs
Conclusion
Docker is the best platform to host your applications quickly and effectively on any OS. Using Docker, you can expedite code deployment, standardize application processes, effortlessly migrate code, and decrease costs through enhanced resource management. Try using Docker to witness the magic of containerization over virtualization and on-premises/Dedicated machine deployments.