In today’s world, containers are the most popular technology which has been using in almost every big empire. So, first of all let us understand what actually containerization is ???
Containerization is defined as a form of operating system virtualization, through which applications are run in isolated user spaces called containers. A container is essentially a fully packaged and portable computing environment, here computing environment is ram and cpu which is the basic requirement to launch an operating system.
So containers are like an operating system but to compute a container is much more easier and fast in comparision to launching an OS with bare-metal approach.
Containers are launched in one go and utilizes very much less resources.
Just like we install virtual machines in our base system, we similarly install containerization tool on the top of our base OS, and then accordingly when the requirement came, we launch multiple containers.
Then what’s the difference between containers and virtual machines ???
Applications running on VM system runs its own OS while applications running in a container environment share a single OS. Thatswhy containers are lightweight, uses very much less resources.
To implement containerization technology, we have number of tools like docker, podman, crio.
So here we will discuss about docker and its some of the commands.“Docker” is containerization technology that enables the creation and use of containers (OS). For installing docker in our machine first of all we need to add docker-ce repo in our redhat system .
We can check from yum repolist command whether the docker repo has been added or not.
So, finally we will install docker in our machine:-
We can check docker version:-
Now we have to start docker services:-
To permanently enable the docker service :-
We will see some of the docker command here:-
- Now we are all set to launch our first docker container, for that we require container image which we download from dockerhub which is a collection of container images. Just like we need iso files for launching virtual machines, similarly we need images for launching containers.
Syntax for the command:- docker pull <image_name>
2. We can list all the downloaded images.
Command: docker images
3. Now, we will launch our centos container .
Syntax for the command: docker run -it centos, this -it is used to get the interactive terminal of the newly created OS. It is the foreground mode taht means the Docker daemon starts the container and attaches the console to stdin, stdout, and stderr to the process running inside the container.
4. Also, if we want to run the container in the background in a “detached” mode, that means docker daemon starts the container in the background and doesn’t attach the console. For that we have -d option and also we can name the container also.
Syntax for command: docker run -dit — name <os_name> <image_name>
5. We can also see the running containers.
Command: docker ps
6. We can stop the container also by docker stop <os_name>/<os_id>
7. We have one command there to list all the stopped and running container at one place. Command: docker ps -a
8. Stopped container can also be started again:-
Command: docker start <os_name>/<os_id>
9. To get the console of the container, we have one command
docker attach <os_name>/<os_id>
10. This command provides more details about a running container, such as IP address. Command: docker inspect <os_name>/<os_id>
11. This command will display messages the container has written to standard error or standard out. Command: docker logs <os_name>/<os_id>
12. To delete all docker images we have one command but for this command to run we have to first stop the container and delete the containers.So, for deleting all containers
13. Now deleting all docker images
Command: docker image rm $(docker images)
We can see there is no image there in our system now :
Thank you for reading :)))