Lang
Blog

Docker — Develop & Deploy Containerized Applications

ByPayal Mittal & Raja Nagori
February 28th . 5 min read
Docker — Develop & Deploy Containerized Applications

Wondering what Docker is? Actually, it’s something worth wondering about. If you’re a Network Engineer or Software Developer, you would already be familiar with Docker- a fantastic tool for developing, shipping and deploying applications within “containers”.

It would be hard not to get attracted to it seeing its amazing ability of containerizing applications.

If you take a dive into the depths of the Internet you would find a whole stack of articles about it but only a few of them are beginner-friendly. Thus, I found myself coerced to write about docker for beginners.

Hopefully, this post will clear all your concepts about docker, and you’ll be able to create your first container.

What is Docker??

Docker is a stateless server that packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime.

Docker is an open-source software platform that lets us build, test, run and deploy applications reliably and quickly. It was launched in the year 2013 by Docker Inc. Since then, it’s been the cause of attraction and excitement among developers across the IT world.

Some short-listed features that make it so popular, are-

  • Compatibility with almost every programming language you’re familiar with.
  • Easier Workflow
  • Agility and Simplicity for Software Development
  • Handy Application Encapsulation
  • Easy Scaling and Monitoring
  • Faster Development & Deployment

Why Do We Need Docker ?

Almost every developer finds himself in such a situation, every so often, when their project works fine as long as its running on their laptop/machine. But, when it is moved onto production state, server or maybe another machine, it usually fails to work even close to fine (and It’s very annoying!). The efficiency, optimization, and performance with which it was working earlier get compromised critically.

You would be baffled to know how frequently these cases come out. The average rate is — about every 3 out of 4 projects.

Likewise, if you develop any website using any framework and move it onto the web server, you’ll definitely face some diminishes and uncertainties.

Docker is an ultimate solution to all these problems and a relief for the developer’s world. In fact, it’s been designed specifically to address and resolve such issues.

Docker Terminology

Let’s understand a few important terms about Docker-

Docker Engine: Docker Engine is a key part of Docker. It is a client-server application, having a CLI (Command Line Interface), Rest API, and a server as its components. It creates and runs the containers from the Docker Image.

docker_1.jpg

Docker Container: A docker container is a standardized, lightweight, stand-alone unit of software that contains entire software/application code, along with its configuration, dependencies, libraries, and tools, all wrapped up into a portable format, ready to run on any computing environments.

You can put these containers anywhere you like and the application will run exactly and absolutely like it was working on your machine.

A docker container is a docker image brought to life.

Docker container is the running instance of the code that was stored in the form of a docker image.

Algorithm for a docker container looks like-

docker_2.jpg

Docker Image: By the term ‘Image’, you don’t need to suppose it to be a picture. The context of Docker Image goes beyond the physical images, they are more like blueprints of a software, holding together the code, libraries, Dockerfile and everything else that needed to run it.

A docker image is a set of stateless and immutable files containing the application code and environment required by an application to run. It’s a read-only file which means you cannot modify it. It will remain like that forever as nothing has ever changed.

What are Virtual Machines (VMs)??

Before containerization entered into the picture, the job of isolating and organizing applications was done by Virtual Machines (VMs).

A virtual machine is a software or virtual server that emulates the functionality of a hardware server. It makes it possible to run what appears to be multiple machines on hardware which actually is a single computer.

The virtual machines run many applications on the same hardware, this process is known as Virtualization.

Both containers and VMs pursue the same goal of isolating the applications and its dependencies in a self-contained unit that can run in any environment. While the VMs virtualize the hardware, containers virtualize the operating system.

So, which one is better??

Now, this is the tricky part. Both play a significant role, depending upon the requirement. While VMs are more secure, containers are still preferred as they are more portable, efficient, flexible, lightweight and, above all, consume fewer resources.

Essential Functions of Docker

There is a long list of tasks that we can do with docker, which is quite impossible for me to explain in this single blog but we will definitely learn about some important ones -

  • Client-side Application Program- You can pack up the whole software code along with its configuration, libraries and move it anywhere you like.
  • It acts as a service and can be deployed on to any server.
  • You can fix the bugs and redeploy the application in the development environment only.
  • Acts as a social networking platform where you can share your work in the form of docker containers.

Understanding Docker with ‘Hello World’ Example

You’re going to learn a lot form this very simple example (If you’re a beginner!!). If you’re a regular user of Docker then it’ll be like a nursery-class lecture.

Starting from the installation, I’ll go through every necessary step such as creating Dockerfile, building, and processing Docker Image, running the container, and a few additional things.

Keep up with me so that you don’t miss anything-

Install Docker:

For Windows:

https://hub.docker.com/editions/community/docker-ce-desktop-windows/

For Linux:

Install some prerequisite packages under the following command-

#Installing some prerequisite packages
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common
#Add the GPG key to the docker repository
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
#Add the docker repository to APT
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
#Update the database
$ sudo apt update
#Install Docker
$ sudo apt install docker-ce

Create a Dockerfile and Index:

I’m sharing an example of creating a simple ‘Hello World’ container in here. Follow me step by step to learn the whole process of building and running a container-

After successfully installing Docker, we will create a Dockerfile-

  • Create a text file named ‘Dockerfile’.
  • Pull the Nginx docker image to serve your static webpage in the Dockerfile, as mentioned here-
FROM ubuntu
RUN apt-get update
RUN apt-get install nginx -y
COPY index.html /var/www/html/
EXPOSE 80
CMD ["nginx","-g","daemon off;"]

Add the commands for a simple web application of ‘Hello World’ in index.html file, like this-

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h2>Hello World</h2>
<p>&copy; Welcome to Docker</p>
</body>
</html>

Note: The index.html and Dockerfile have to be saved in the same directory.

Create a Docker Image:

To build the docker image, run the command-

docker build -t hello_world .

Note: “hello_world is the name of the docker image.”

Run the Docker Container:

After the successful build of the docker image, run the container with the following command-

docker run -d -p 8080:80 hello_world

To check the running container or to render the docker container on the web browser you need to hit the URL-

http://localhost:8080

Output goes here -

docker_3.jpg

Note: The -p parameter represents the port number. Any web application is run on a browser with a specific port number.

For example-

8080:80 means all the requests hitting on port 80 will bind to 8080 port only.

Additional:

#To check the status of your docker container
docker ps
#To enter into the docker container
docker exec -it <container ID> bash
#To check the logs of running container
docker logs <container ID>

Once you’re done by creating a Docker Image, you can share it on Docker Hub and make it public.

Future with Docker/ Business Value of Docker

Do you have any rough guesses about what is the statistical condition of Docker in the marketplace?? Not even close?? That’s fine, let me break it to you that more than 15,000 companies are currently using Docker.

The pie-chart below will picturize the general usage of Docker in the international market-

docker_4.jpg

With 40%, Software companies have occupied the majority of ratio. Then comes IT field with 17%, followed by HR & Recruiting industry with 10%.

The remaining proportion is covered by Telecommunications, Hardware, Consulting, Healthcare, Accounting, Socializing, and Retail industries. With every passing year, the pace of using Docker is increasing at a high rate, in each and every niche.

Parting Words:

From the very moment when Docker was first introduced, it’s been easing the lives of developers. There have been a few misconceptions about Docker, such as, it’s not secure, requires Cloud, and all, but it has ruled them all out.

As a result, most of the companies have started shifting towards containers-driven environments.

The unbound flexibility and portability of Docker makes it a powerful tool. And who knows what the futuristic Docker has in store for us??

Thanks for reading this blog. Hopefully, you liked it. If it’s a yes, then stay connected with us.

Share:
0
+0