At first, forget about this docker for a while, and let's see some backstory.
Regarding it, let us assume if Docker was not there, this is how it would be
It's like sinking our applications. The context of sinking means the developers are facing issues in the production phase; for example, the application works fine on the developer's machine but not on the user one; the applications will not run properly.
BEFORE DOCKER
At that time, the company needed a server to run an application, but if there were multiple applications, we needed to have more servers, and the cost was too high. Then we came a long way to develop virtual machines
VIRTUAL MACHINES -
So these VMs solved many problems of having multiple servers in one machine we can have a windows server in mac or Ubuntu, but again there was a problem with running a virtual machine. We need to have separate OS(operating system) and RAM as well, so it's a drawback for VMs, and VMs are costly.
Thats why developers developed a concept called CONTAINERS, CONTAINERS, CONTAINERS....
Now let's see what these containers are!!
CONTAINERS -
Now let us take a scenario where you develop an application or software, and let's think it has various subparts (EX-source code, database, frontend, backend etc.). Is it reasonable to shift part by part or all parts as a single unit? It's all a time, and this thing is done by CONTAINERS
Containers are virtual machines but don't have an individual operating system; they have only one container engine, and containers are lightweight.
And these containers are very efficient in running, deploying and scaling applications.
But to run containers, we need to have a host operating system and container engine.
now you get clarity b/w the difference of VM'S AND CONTAINERS lets look at the image below
It is Docker's backstory, and now let's jump into our main important topic.
DOCKER -
So we see about Docker; let's go.
Docker is nothing but a container platform. Once you see the above logo of Docker, we can observe that its a platform which can have many containers on it, which mean it can build, test and deploy applications rapidly
And remember, we store the applications created by developers in the form of containers, example, which you see on the Docker logo(above)
So the developer who is developing the application stores all the dependencies in the form of a Docker file
I hope you are clear till this point.
And now, using this Docker file we create a thing called docker image,
wait, let me give good clarity reg this Docker image-
--- docker image is nothing but a template where it has a set of instructions to build a Docker container. And assume that the image means it's like a snapshot of instructions.
- We mainly use docker for Microservices, Data Processing, Continuous Integration and Delivery, and Containers as a Service.
Now we see about Docker architecture //
DOCKER ARCHITECTURE
The main components of Docker are:
Docker daemon
Docker client
Docker Registries
Docker file
Docker host
Now we read about each component individually and let's know their uses//
Docker daemon
Daemon is the main thing in Docker; it is a place where decisions are made, it gets API requests from the Docker client, and it can manage Docker objects such as images, containers, networks and volumes.
Docker client
For communication, we take the help of the Docker client, where our requests are sent to a daemon when we use the command docker, And this client can communicate with more than one daemon.
Docker Registries
Registry is nothing, but it registers or stores the location of the Docker image
Docker hub is a public registry where we can pull images which are already created to develop our application
And the image we pull needs to store somewhere right, so it sits in our local computer on Docker_host.
Docker file -
To create a Docker image, we need a docker file containing predefined data.
And with this image, we can create a container in any environment
We can store these images in the DockerHub as public or private images, where other users can access public images, also
example of Docker file
FROM ubuntu
MAINTAINER shyam <shyam@gmail.com>
RUN apt-get update
CMD [“echo”, “Hello World”]
Docker host -
Docker Host intends to offer an environment that is ready for running and executing the applications.
Docker Host comprises docker images, daemon, Networks, Storage, and Containers.
Host networking has a different set of advantages for Docker Host and the platform as a whole.
Installation
now lets see some basic commands for docker
Basic commands -
- docker version – Echoes Client’s and Server’s Version of Docker
- docker images – List all Docker images
- docker build <image> – Builds an image from a Docker file
- docker save <path> <image> – Saves Docker image to .tar file specified by path
- docker run – Runs a command in a new container.
- docker start – Starts one or more stopped containers
- docker stop <container_id> – Stops container
- docker rmi <image> – Removes Docker image
- docker rm <container_id> – Removes Container
- docker pull – Pulls an image or a repository from a registry
- docker push – Pushes an image or a repository to a registry
- docker export – Exports a container’s filesystem as a tar archive
- docker exec – Runs a command in a run-time container
- docker ps – Show running containers
- docker ps -a – Show all containers
- docker ps -l – Show latest created container
- docker search – Searches the Docker Hub for images
- docker attach – Attaches to a running container
- docker commit – Creates a new image from a container’s changes
- docker network ls
- docker network create *network_name*
Now lets talk about docker objects its important read with little love
Layers on image
the image consists of a read only docker file
where if we need to modify it only a layer of it is modified and we can write a code to in that layer
we as a developer cant change everything because its only in the format of read
Networking
Docker Networking allows you to create a Network of Docker containers managed by a master node called manager.
the communication between the containers in docker happens through sharing of network packets.
when they are in the same network they can talk using container name.
but when a container needs to communicate with the container of different network then it can establish a communication using local host and port No.
-docker network ls
- docker network create *network_name*
Storage -
to store the data in a container we need storage drivers
The storage is non-persistent, for which the data will perish anytime the container is not under the run. In terms of persistent storage, Docker intends to offer few options that include:
. Data Volumes
. Data Volume Container
. Directory Mounts
. Storage Plugins
and its end.