Containerization using Docker

Sumant Mishra
3 min readJul 5, 2019

Here I have tried to give a basic understanding of Docker, Containers, Images and how to use them together.

What is Docker?

Docker is a software platform which allows developers and system admins to develop, test and deploy the applications quickly. Docker provides an isolated environment in which all the required libraries, system tools, code, runtimes or databases etc. related to your application can be packaged, deployed and scaled into any environment. And application will run exactly in similar way as it runs in the developed environment.

This isolated environment is called as containers and use of these containers to deploy and applications is called containerization.

Below are few advantages which make containerization increasingly popular:

  • Lightweight: Any type of complex applications can be containerised and deployed by leveraging and sharing the host kernel.
  • Portable: Applications can be built locally, deployed locally or in the cloud run anywhere.
  • Scalable: Updates and upgrades can be applied on-the-fly. Container replicas can be increased and distributed automatically.

Difference between VM and Container

With Virtual Machine, several virtual machines can run in the host machine. Each Virtual Machine is an isolated system which has its own full-blown guest OS with its own kernel. Applications run on top of these Operating systems. However, all the containers share the common Server/host machine, OS and kernel. And containers are just tiny processes run on the same machine.

Docker objects

This section is a brief overview of some of the key Docker objects which are must to know before working:

Image

A Docker image is an executable read-only template which can be instantiated to create containers. The image contains everything needed to run an application like code, libraries, configuration files and other dependencies. Below command can be used to list all the docker images in terminal:

docker images ls

Users can create their own image by packaging and pushing their code to docker hub or download existing images from docker hub.

Container

A Docker container is a runtime instance of a Docker image. A container can be instantiated by using images available locally or can be pulled from docker hub.

Below command can be used to list all the containers:

docker ps

or

docker container ls

Dockerfile

A Dockerfile is a text file which contains all the commands or instructions required to assemble an image. This works as batch script. Docker builds images automatically by reading the commands/instructions from that Dockerfile. File name should be exactly Dockerfile without any extension. And this file should be located at the root of the project folder. Below command is used to build the docker image:

docker build -t [image name] .

Below is the content of a sample Dockerfile:

Docker hub

Docker hub is a registry service on the cloud which allows to download (pull) existing images built by others. Or any signed in user can upload (push) his own Docker images to Docker hub. Below are few commands used to push images to docker hub registry:

docker tag [image id] [username]/[image name]:[tag]

docker push [username]/[image name]

Some basic commands

Thanks!

--

--

Sumant Mishra
Sumant Mishra

Written by Sumant Mishra

Fullstack Architect || TOGAF 9 || AWSCSAA || Cloud Practitioner || NodeJS || React & Angular || Docker || Coder

No responses yet