Docker Commands: A Comprehensive Guide

My name is Hamza Rehman. I'm a passionate DevOps enthusiast. With a deep interest in open-source technologies and automation, I enjoys to share my knowledge and insights with the community.
Docker has revolutionized the way developers build, ship, and run applications by enabling containerization. Docker containers provide a lightweight, portable, and isolated environment for running applications consistently across different platforms.In this guide, we'll explore Docker commands.
Basic Docker Commands:
- docker run: The fundamental command to create and start a container based on an image.
docker run nginx
docker run --name my-nginx -d -p 8080:80 nginx

docker ps: Lists all running containers.
docker ps

docker images: Lists all locally available Docker images.
docker images

docker pull: Fetches an image from a registry.
docker pull nginx

docker build: Builds an image from a Dockerfile.
docker build -t <image_name> <path_to_Dockerfile>
docker stop: Stops a running container.
docker stop <container_id>

docker start: Starts a stopped container.
docker start <container_id>

docker restart: Restarts a container.
docker restart <container_id>

docker logs: Retrieves the logs of a container.
docker logs <container_id>

docker inspect: Provides detailed information about a container or image.
docker inspect <container_or_image_id>

docker rm: Removes one or more stopped containers.
docker rm <container_id>

docker rmi: Removes one or more Docker images.
docker rmi <image_id>

