Hello! ๐ This blog is about Docker. Feel free to check it out and share your thoughts. ๐๐ก
Before Jumb into Docker let's understand what is the difference between the Virtual Machine and Docker.
Virtual Machine (VM) ๐ฅ๏ธ๐ : A virtual machine is like having a separate house ๐ built within your own house ๐ก. It's a fully isolated and self-contained environment that can run its own operating system and applications. It's like having a mini-computer inside your computer.
To create a virtual machine, you need a software called a hypervisor, which acts like a construction manager. The hypervisor sets up the virtual house and allocates resources like CPU, memory, and storage. You can install any operating system and applications you want inside the virtual house.
However, running virtual machines can be resource-intensive and slow because each virtual machine requires its own complete operating system, which takes up a lot of memory and storage space. It's like having multiple houses with duplicate furniture and appliances.
Docker ๐ณ: Docker, on the other hand, is like having different sections within the same house ๐ก. Instead of building separate houses, you create lightweight containers ๐ฆ within the house that share the same resources.
Containers are like individual rooms that are isolated from each other, but they all use the same underlying operating system. Docker allows you to package your application and its dependencies into a container, which contains everything needed to run the application.
Containers are lightweight and share the host system's operating system, making them faster and more efficient than virtual machines. It's like having multiple rooms in the same house, sharing common furniture and appliances, which saves space and resources.
In summary, virtual machines are like separate houses, each with its own operating system, while Docker containers are like different rooms within the same house, sharing the host system's operating system. Docker containers are more lightweight, efficient, and easier to manage compared to virtual machines. ๐ ๐ฆ
What is Docker?
Docker is a tool that helps package up computer programs and all their dependencies into a self-contained container. It makes it easy to share and run programs on different computers without worrying about compatibility issues. It's like a special box that holds everything your program needs, making it simpler to use and share with others. ๐๐ป
Docker was first released in March 2013. It is developed by Solomon Nykes and Sebastian Pahl.
What is Image?
Image is the blueprint of a particular application and its dependencies required to run the application.
What is Container?
A container is like a package that holds both the application software and its dependencies.
Why are Containers lightweight?
Containers are lightweight because they only include what's necessary for running an application. They don't need a whole operating system like virtual machines do. Instead, they share the host operating system, which saves space and resources. Containers also share common parts, like libraries, so they don't carry extra weight. This makes them start up quickly and easy to move around. Their simplicity and efficiency make containers a popular choice for running applications.
I hope you already have Docker installed, as this blog is part of the 90 Days of DevOps challenge. I will now jump straight into Docker commands. If you need more details, make sure to check out some useful links about Docker provided below.
Docker Commands.
docker version
---To check the version of the Docker.docker run hello-world
--- The docker run command is used to start a new container. In this example, we're running the hello-world image, which is a simple image that prints a "Hello World" message. When you execute this command, Docker pulls the hello-world image (if not already present) and runs it in a new container. The container prints the message and then exits.docker inspect <container_id>
--- The docker inspect command provides detailed information about a container or image. Replace <container_id> with the actual ID or name of the container you want to inspect. It returns a JSON-formatted output containing various details such as network configuration, environment variables, volume mounts, and more.docker port <container_id>
---- The docker port command lists the port mappings for a container. Replace <container_id> with the ID or name of the container you want to inspect. It displays the mapping between the container's internal ports and the corresponding external ports on the host machine.docker stats <container_id>
--- The docker stats command provides real-time resource usage statistics for one or more containers. Replace <container_id> with the ID or name of the container you want to monitor. It displays information such as CPU usage, memory consumption, and network I/O for the specified container(s).docker top <container_id>
--- The docker top command allows you to view the processes running inside a container. Replace <container_id> with the ID or name of the container you want to inspect. It lists the running processes along with details such as process ID, user, CPU usage, and memory consumption.docker save image.tar <image_name>
--- The docker save command saves an image to a tar archive. Replace <image_name> with the name or ID of the image you want to save.docker load -i image.tar
--- The docker load command loads an image from a tar archive. The -i option specifies the input file name. In this example, the image will be loaded from the image.tar file.
Starting Nginx Server web Server .
Lets start ; ; ; ; ; ; ;
- To run the Nginx we use the following command.
docker container run --publish 80:80 nginx
or docker run -p 80:80 nginx
This command directly starts the nginx server ....................
type localhost:80 or instance IP:80 on your browser.
How it happen ---- the docker engine looked for an image called nginx, and it pulled from the docker hub, download the image then started the new container.
The publish port command exposes the local port on the instance and sent all the traffic and the Nginx web server default port 80 and traffic just forwards automatically....... through my browser to my local host and into that container.
To stop the running container just press Ctrl+C
You can run the container in detached mode as a result you screen clean even though the nginx is running in the background.
docker container run --publish 80:80 --detach nginx
or docker run -p 80:80 -d nginx
Now let's see the list of containers by using the command
docker container ls
ordocker ps
To stop the running container you can use --
docker container stop <container ID>
ordocker stop <container ID>
the ls command only shows the running containers.
To see the stopped container you can add
-a
.docker container ls -a
ordocker ps -a
To give a name to your container
docker container run --publish 80:80 --detach --name web_blog nginx
ordocker run -p 80:80 -d --name web_blog nginx
Observe the name section name: web_blog is present.
To see the Latest log for the running container docker--
container logs <name of the container>
ordocker logs <name of the container>
Now that we have come to an end, let's clean up the containers and images.
Use
docker rm
to remove the container, anddocker rmi
to delete the image.
I hope this blog has been helpful. Be sure to check out my next blog for more information on Docker. ๐
Happy learning! ๐
useful links:
https://scriptsbyshruti.hashnode.dev/docker#heading-architecture-of-docker