Hello folks I am here again after a long time on this beautiful platform.
Now we are going to know about a very exciting topic which is #Docker.
we are going to start with what is Docker?
docker was first introduced by Solomon Hykes and Sebastien Paul in March 2013.
Docker is an open-source centralized platform designed to create deploy and run applications.
It is a tool we use to deploy and run an application.
Why Docker was introduced what was the reason behind that?
As we know that we use docker to deploy and run an app in it.
What used to happen before 2013 whenever a DevOps Engineer wanted to deploy and run an app so he had to download all the required stuff.
It was very costly to afford because for an application you are wasting so much space and money on an application.
That was the reason behind launching docker.
How does docker work?
For understanding docker you need to understand containers. The container is a kind of virtual world for an application that provides all the requirement(Those technologies from which the app is built by the developer ) those containers are used to run on the layer called Docker Engine.
There is an important term called hypervisor layer, so Docker cannot be set up on the os directly. That's why we use a hypervisor layer. whatever will be the need of the Docker engine from the os it will ask to hypervisor and the hypervisor take those important stuff from the os and provide it to the Docker engine. so basically hypervisor is the only way for the Docker engine to connect with the operating system.
Docker contains containers where an app used to run and there is a term called Docker Engine. Docker Engine used to be set up on the hypervisor layer. Docker Engine uses to tell the hypervisor all requirements that it needed from the os.
How we can create containers?
- For creating containers we have first to create the docker file and make an image via this command [docker build -t <image name>] out of it and run the container via this command[docker run -it --name <name of container> <image name> /bin/bash].
Advantages of Docker
No pre-allocation of RAM.
CI Efficiency -> Docker enables you to build a container image and use. that same image across every step of the deployment process.
Less Cost.
It is light in weight.
It can run on physical Hardwar, Virtual Hardwar, or on the cloud.
You can re-use the image.
It took very less time to create the container.
Disadvantages of Docker
Docker is not a good solution for an application that requires a rich GUI.
Difficult to manage a large number of containers.
Docker does not provide cross-platform compatibility means if an application is designed to run in a docker container on Windows, then it can't run on Linux or vice versa.
Docker is suitable when the development O.S and testing O.S are the same, if the O.S is different, we should use Virtual Machine.
No solution for Data Recover and Backup.
Docker Deamon
Docker daemon runs on the Host O.S.
It is responsible for running containers and managing docker services. Docker daemons can communicate with other daemons.
There are some commands in Docker
This is a command for downloading docker in Linux
-> sudo apt-get install docker .io
to see all images present in your local
-> docker images
to find out images in the docker hub.
-> docker search <image>
To download an image from docker-hub to a local machine.
-> docker pull
to give a name to the container and run.
-> docker run -it --name <name of container> <image name> /bin/bash
to check, whether the service is starting or not
-> service docker status
to start the service.
-> service docker start
to inside the container
-> docker attach <container name>
to see the running containers
-> docker ps
to see the containers
->docker ps -a
to delete the containers
->docker rm <container name>
Exiting from the docker container
-> exit
to delete image
-> docker image rm <image name>
to create an image of this container.
-> docker commit <comtainer_name> <container_image name>
to create an image out of Dockerfile
-> docker build -t <image name>
Docker swarm
container orchestration tool
deployment and maintenance of multiple containers and services for an application manage a cluster of Docker nodes.
deployment
Scaling
Resource Allocation
Load balancing
health monitoring
Components
Service: Defines Task that needs to be executed on the manager and worker node Task: they are the docker containers that execute commands
Manager node: Takes the commands to create services, allocate )Ps, assign Tasks.
Worker Node: Performs the task of running a container.
Docker swarm commands
Initialize a swarm in the master node
->sudo docker swarm init
Give the info about the docker engine
-> sudo docker info
Show docker swarm nodes
-> sudo docker node ls
Create a service
-> sudo docker service create --name <service name> --replicas 3 --publish 8001:8001 <image>
Sow running services
-> sudo docker service ls
Remove a service
-> sudo docker service rm <service name>
Join a swarm
-> sudo docker swarm join --token <token>
Generate a token from the manager
->sudo docker swarm join-token worker
Leave a swarm
-> sudo docker swarm leave