To begin with Docker(containers)

sonu kushwaha
5 min readNov 10, 2020

Have you ever faced with the problem of a single application behaves differently on different system ,but works fine on the system on which it was developed.here is the solution .

Before we begin, let’s understand the brief, about Containers and Virtual Machines(VMs)

CONTAINERS:-
containers are an abstraction at the app layer that packages code and dependencies together. one can run multiple containers on the same machine
as it(container) does not require full OS what it does is simply shares the same OS kernel with other containers but each running as an isolated
processes in the user’s environment(space).

VIRTUAl MACHINES:-
virtual machines are the abstraction of physical hardware which converts one server to multiple servers which are done by setting up hypervisor(what it does is divides the resource of the physical hardware accordingly as per num. of VMs )and NOTE:- each VMs has it own full fledged OS. VMs are actually slow to boot.

What is Docker?
Docker is a tool for running applications in an isolated environment(container tech.) that allows you to build, test, and deploy applications quickly.
it is very similar to a virtual machine but it's much faster, does not require a lot of memory and the entire OS to operate, the cool thing
about DOCKER is that your app run in the exact same environment if I work in my machine then it will definitely work under your machine too.
(if it works in the staging environment then it will also work in the production environments ) so, this is one of the benefits of the docker.(NOTE:- docker environment should be pre-installed on the system. ) and nowadays it has become the Standard for software deployment, everyone is adopting docker in their workflow
for deployment, because it makes it easier for packaging application, one does not need to deal with different OS and distribution which can vary from system to system
A developer defines all the applications and its dependencies in a Dockerfile which is then used to build Docker images that defines a Docker container.
Doing this ensures that your application will run in any environment.

WHY SHOULD I LEARN DOCKER?
- container run/boot in seconds instead of minutes
-container requires fewer resources results in less disk space and memory as well.
-containers do no require full OS, ie uses as per needs
-testing and deployment are easier in the case of containers

but.. one must know that even if the containers have the upper hand ie over VMs, in some of the places container can not replace the VMs. like all the cloud providers GCP, ASURE, AWS, DigitalOcean, and many more. also, there are many of the jobs that are specifically done by VMs only.

installation of Docker:- (visit this link)

UNDERSTANDING DOCKER ARCHITECTURE:
Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers.

Docker daemon
It listens to the API requests being made through the Docker client and manages Docker objects such as images, containers, networks, and volumes.

Docker client
This is what you use to interact with Docker. When you run a command using docker, the client sends the command to the daemon, which carries them out.
The Docker client can communicate with more than one daemon.

Dockerfile
what it does is, Describes steps to create a Docker image. It’s like a recipe with all ingredients and steps necessary in making your dish. This file can be used to create Docker Image. These images can be pulled to create containers in any environment. These images can also be store online at docker hubs. When you run docker image you get docker containers. The container will have the application with all its dependencies.
-Create a file named ‘Dockerfile’
-By default on building, docker searches for ‘Dockerfile’

FROM ubuntu

MAINTAINER sonu kushwaha <sksonukushwaha403@gmail.com>

RUN apt-get update

CMD [“echo”, “Hello World”]

$ docker build -t myimage:1.0 .

-During building of the image, the commands in RUN section of Dockerfile will get executed.
$ docker run ImageID
-The commands in CMD section of Dockerfile will get executed when you create a container out of the image.

Docker Image

A Docker Image is a file that defines a Docker Container. It is similar in concept to a snapshot of a VM. A container that moves from one Docker environment to another with the same OS will work without changes because the image includes all of the dependencies needed to execute the code. Docker Image is run to create a docker container. Images are immutable. Once built, the files making up an image do not change. Images can be stored locally or remote locations like hub.docker.com.

One can easily use predefined or pre-build images that are present at DockerHub, with the command

$docker pull ImageID

Container

It is nothing but the running instance of Image(dish)

$ docker run ImageID

if the image is not present in the system, it will pull image on its own and then runs the image, and creates the running instance of image.

Basic Commands

$ docker ps (list all containers)
$ docker run ImageName/ID (checks locally for image, if not available it will go to registry and then go to DOCKER_HOST)
$ docker start ContainerName/ID
$ docker kill ContainerName/ID (Stops a running container)
$ docker rm ContainerName/ID (Deletes a stopped container)
$ docker rm $(docker ps -a -q) (Delete all stopped containers)

what if ,you have a large number of containers running and it’s getting difficult to manage all of them. so what we need is managing containers, hence we need Container-orchestration system.and Kubernetes is one of the most famous container orchestration engine.

CONTACT:- Linkedin Twitter GitHub

--

--