What is Docker?

Docker is a platform or ecosystem around creating and running containers.

When we run any docker command. 
1) The Docker CLI reaches out the Docker Hub.
2) Docker Hub downloads a single file called  “Image”.

Image: This is a single file which has all the  dependencies and configurations that are required to run a very specific program. This will be available on our hard-drive.By using this image we can create a container.

Container: Is an instance of an image which has  own isolated hardware resources .Runs a program.

Why to use Docker?

This entire flow will be taken care by Docker

Docker makes installation very easy without worrying about the setup or dependencies.

Installing docker for Windows/Mac:

On Mac:
Requirement: OS X Sierra 10.12 or newer macOS releases.

Steps involved while running the docker commands.
docker -version gives

Installing docker on Windows System:

If you are a Windows Home user, you will not be able install the Docker for Windows Desktop edition, as it requires Hyper-V virtualization. This is supported only by Windows Professional and Enterprise editions.

Windows Home users will need to install Docker Toolbox which uses VirtualBox instead. Please follow the instructions below for installation:

https://docs.docker.com/toolbox/toolbox_install_windows/

You may also need to enable virtualization in your computer’s BIOS settings. This will be different for each manufacturer, please refer to their documentation on which keys to use to access these settings on reboot.

*Note*
A major difference between using Docker Desktop vs. Docker Toolbox is that you will not be able to use localhost anymore.

Instead, you will need to access your machine with the IP address.

Windows Professional and Enterprise Edition:

After installing docker from the “Docker for windows” setup file that you got from the docker.com. You will get the below popup while trying to run the docker.

You need enable this from your Bios settings

With this you are done with installing/setting up docker on your machine.

How Docker Client Works:

As I shown in the above example of hello-world, when we run the docker run command for the first time docker will get that image from docker hub and place it in local image cache.

What is a container and how it is created on our local machines:

Container is a process or set of processes that has grouping of resources specifically assigned to it.

Relation between Image & Container


  1. An image is nothing but a file system snapshot which contains folders or files that undergoes into simple copy paste.
  2. Image also contains some specific startup commands.        
  3. The kernel reserves some space in the hard disk for the container and copy of the FS snapshot files to that space. By this our image will install jenkins and java centos on our system.
  4. Now when we run the startup command it will execute the specific process(Running process) and this process will be isolated to the resources that are in that container.

The entire process is taken place based on the kernel and its namespacing and this is available only on linux. Then we will get a doubt that how a docker is running on Windows/Mac OS?
Below diagram depicts you behind the scenes of Docker installation.


On Mac/Window OS when we install docker it will install Linux Virtual Machine  first where all our containers will be created.


Linux kernel will be hosting the Running processes inside the containers and this linux kernel will decides the limitation of access or constraints the access or isolating the access to different hardware resources on your computer.

Practically you can check this linux virtual machine on your system by running “docker version” command from your command prompt or terminal.

In server section your can find “Os/Arch : Linux/amd64”.

To List out all the containers running on your system:

The below command gives a table which shows the details of the containers those are running currently on your system.
> docker ps

CONTAINER ID   IMAGE    COMMAND  CREATED  STATUS  PORT  NAMES

To get all the containers details those are created over the time run below command

> docker ps --all
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
1d7338d69210        hello-world         "echo ji"           12 minutes ago      Created                                         elated_dhawan

00d399cbcb2c        hello-world         "ls"                12 minutes ago      Created                                         ecstatic_swanson

d635b43b50fe        hello-world         "/hello"            12 minutes ago      Exited (0) 12 minutes ago                       elegant_shockley

0ef5dbd3889b        hello-world         "ls"                12 minutes ago      Created                                         determined_ardinghelli

834ec50dd27c        busybox             "ls"                13 minutes ago      Exited (0) 13 minutes ago                       jolly_kapitsa

0f228d45df6d        hello-world         "/hello"            6 days ago          Exited (0) 6 days ago                           goofy_swanson

63f20f412432        hello-world         "/hello"            7 days ago          Exited (0) 7 days ago                           gifted_sammet

Life cycle of a container:

When ever we ran the command “docker run” this means it will first create the container from image and start that container by using it’s container ID.

Docker Run = Docker Create + Docker Start

Create command gives the id of the container.

> docker create hello-world

O/P: 6ee98f206551081fdde42089b6d289fccc6367e02a286be9d1f8e7af4c9de2b0
> docker start -a <Container Id>
> docker start  -a 6ee98f206551081fdde42089b6d289fccc6367e02a286be9d1f8e7af4c9de2b0

O/P: This will print the original output as show in the previous images. 

The "-a" argument will actually watches for the output and prints the output to the terminal.

Building Custom/Personalized Images Through Docker Server:

To create a customized docker we need to go through the below flow diagram:

Creating a Docker File:

Common steps to create any docker image.

1) Goal: Create an image that runs Jenkins-Server ( > represents Command prompt/Terminal).

* > mkdir jenkins-image 
(Create a directory anywhere on your computer)

> cd jenkins-image

Create a new file with file name "Dockerfile" starting with capital "D" without any extension and add below lines.

=> Inside Dockerfile
# Use an existing docker image as base
FROM ubuntu:16.04
#Download and install a dependency
RUN useradd -d "/var/jenkins_home" -u 1000 -m -s /bin/bash jenkins
RUN mkdir -p /var/log/jenkins
RUN chown -R jenkins:jenkins /var/log/jenkins

# Tell the image what to do when its start 
# as a container
VOLUME ["/var/log/jenkins", "/var/jenkins_home"] USER jenkins
CMD ["echo", "Data container for Jenkins"]

2) Goal: Create an image that runs redis-Server ( > represents Command prompt/Terminal).

* > mkdir redis-image 
(Create a directory anywhere on your computer)

> cd redis-image

Create a new file with file name "Dockerfile" starting with capital "D" without any extension and add below lines.

=> Inside Dockerfile
# Use an existing docker image as base
#FROM alpine

#Download and install a dependency
RUN apk add --update redis

# Tell the image what to do when its start 
# as a container
CMD ["redis-server"]
===============END OF the File save it=======================

From command prompt run 
> pwd
/redis-image

> docker build .
Successfully built f5fb02a2ce07

Now run
> docker run f5fb02a2ce07 
..................
....................
Ready to accept connections

Conclusion: In this post we discussed
1) What is docker?
2) Why we need to use it
3) How to install it
4) Image Vs Container
5) Creating Custom docker

I hope you all got the overview of docker and dockerization.

Categories: General