Docker basics and Installation guide (Ubuntu)

Today we will see some basics of Docker and Installation of Docker on Ubuntu virtual machine. In basics we will see what is Docker and why we need Docker. This article will be short with very simple steps. You will find lots of articles and tutorial on Docker. I am also trying to put in simple words with some images for reference.    

What is Docker

Docker is an application which provides you functionality of Deploying your application inside of “Container” with the additional layer of abstraction of virtualization on host operating system. Important benefit of Docker is you can add your application with all its dependency in one package.When you run this package, it deploy and configure all prerequisites with one go.

What is Container

Container is an abstraction at the app layer that packages code and dependencies together. Containers are isolation part of Operating system. It’s a packages which contains code and all its dependency. This containers can be created on the fly to deploy particular application with its dependency. This container can be windows , Ubuntu or any other. Multiple Containers can run on the same machine and share Operating System Kernel.

Benefits of Docker

Reduce cost of Infrastructure

The bigger advantage of using Docker is Cost saving. The biggest driver of most management decision to move to new Product is Return on Investment. Using Docker for your solution is like saving cost on Infrastructure. Organization don’t need big servers and its security. Also they don’t require employee to maintain this servers.

Consistency of Product Environment

Normally we get words from Development team “It is working on my machine”. Many times we face this issue same application work with one server but not with another server. There can be different reasons for this failure but it’s always related to infrastructure or some other dependent applications. Docker can resolve this problem permanently.  Docker container configures all dependency which require your application. So it will be consistency on each product environment.

Fast Deployment

In real scenario if you are not using Docker you always need to install / configure prerequisites for your application on server which takes lot of time. You need to make sure all required configuration is complete. With Docker container you just need to run container which makes sure all required configuration is done.

Multi cloud support

Now already all major cloud provider has supported Docker with their services. You can see Docker container can run inside AWS (Amazon Web Services), MS Azure  and GCP (Google Cloud Platform). So in this case of you want to run same container on Azure and AWS as well then it will work without any issue.

Isolation

Isolation is also important quality of Docker. If you are running multiple applications in multiple containers on same machine then Dockers make sure there will be isolation in between each containers.  Every resources and application in every container is isolated and segregated.

Security

If you talk about Security then Dockers make sure no Docker containers can look into process running into others containers. As Isolation is key benefit of Docker.

Install Docker on Ubuntu

Docker installation on Ubuntu is very easy. I can show you it in simple steps. I have newly created Ubuntu 18.4 virtual machine. First we need to SSH into this Ubuntu VM. You can download Putty application from here to do SSH. Use public IP of VM.

Once you are inside Virtual machine , first thing you need to do is execute below command.

The scripts require root or sudo privileges to run. Therefore, you should carefully examine and audit the scripts before running them.

$ sudo su

Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

$ sudo apt-get update     

To install Docker use below command

$ wget -qO- https://get.docker.com/ | sh

Installation completed

Once installation complete you can see output like above. You may also get warning for some compatibility features.

How to check Docker version

$docker version

Check details of installed Docker

$ docker info

You can see some warning at the end of this output,  it may include warning about functionality which don’t support by host operating system. For now you can ignore such warning.

Docker Hello-World

After successful installation of Docker, to verify its installation you can execute pre build Docker image

  • Images -> Images are stopped container
  • Containers -> Containers are running images

$ docker run <image-name>

Docker Run command create new isolated container form Image. Its first check your local images list if it don’t find image locally it goes to public repository (hub.docker.com). It pulls latest version of that image and execute it locally.

$ docker pull <image name>

Docker pull command pulls / downloads images from repository on your local repository  

When you install Docker it gives you Client and Daemon on the same host.

When you call docker run command with Client it always first make call to Daemon.

If client don’t have particular image which you called then its redirect call to Docker public repository (hub.docker.com) below image can explain you same flow.

$ docker rmi

Remove or delete image from locally. If you pass image ID then it will delete one single image.

In below example you can there are images and I am removing Ubuntu image with image ID.

List of basic commands

docker runTo run new container
docker psTo see list of container running and stopped
docker imagesTo see info about images
docker rmiTo Remove Docker images from locally
docker pull <image name>To download image from public repository