Day 18 : Some basic docker commands

#90daysofdevops #devops

In the last 4 blogs, I was talking about images and containers. But we wonder how we can create them.

Let's talk about that today!

Docker Image: You can create an image using dockerfile or docker-compose, but we will come to that point later in a future blog.

Firstly, we will check how to pull an image from DockerHub. You can pull any image from DockerHub by using the below command.

docker pull <image-name>

After pulling the images you can list all the images by using the below command:

docker images

To delete an image, you can use "docker rmi <image-id>"

Docker Container:

To run a container from an image we need to run that image.

docker run -it -d ubuntu

here "-it" option is used to make it interactive and "-d" is used to run it in the background.

And you can list all containers by using the "docker ps" command.

Note: "docker ps -a" will show the stopped containers as well.

Below are some frequently used commands in docker:

docker inspect :

docker inspect is used to see the details of Docker objects. Those objects can be docker images, containers, networks, volumes, plugins, etc. By default, "docker inspect" returns information in JSON format.

docker inspect <id>

docker port:

The “docker port” command is used to list the port mappings for a container.

docker port <container-name/id>

docker stats:

The docker stats command is used to display real-time resource usage statistics for running containers. It provides information such as CPU usage, memory usage network I/O, and block I/O of each container.

To limit data to one or more specific containers, specify a list of container names or ids separated by a space. You can specify a stopped container but stopped containers do not return any data.

docker stats Container_ID

docker top:

This command shows you the processes running inside a container. Note that it does not provide you with real-time updates.

docker top <container-id>

docker save and docker load :

docker save command helps us to save one or more images to a tar archive and then we use the docker load command to load images from a tar archive

docker save -o image.tar image:tag

Note: "-o" writes to a file, instead of STDOUT.

The docker load command restores the saved images into your local Docker environment, making them available for use.

docker load -i image.tar

Note: "-i" reads from the tar archive file, instead of STDIN.

If this post was helpful, please follow and click the 💚 button below to show your support.

_ Thank you for reading!

_Sudipa