Essential Docker Commands: A Beginner's Guide

๐ข 1. Basic Docker Commands
| Command | Description |
docker --version | Shows the installed Docker version. |
docker version | Displays detailed client & server version info. |
docker info | Displays system-wide Docker info (containers, images, drivers, etc.). |
docker help | List Docker commands and usage help. |
docker system df | Shows disk space usage by Docker. |
docker system prune | Removes all unused data (containers, images, volumes, networks). |
๐ต 2. Docker Image Management
| Command | Description |
docker images | Lists all available images on the system. |
docker pull <image_name> | Downloads an image from Docker Hub (or registry). |
docker build -t <name>:<tag> <dockerfile_path> | Builds an image from a Dockerfile located at given path. |
docker rmi <image_id> | Removes a Docker image. |
docker image prune | Removes all unused images. |
docker history <image_name> | Shows the history/layers of an image. |
docker tag <local_image> <username/repo:tag> | Tags a local image for pushing to registry. |
docker push <image_name>:<tag> | Pushes an image to Docker Hub (or registry). |
docker save -o <file.tar> <image_name> | Saves an image to a tar archive. |
docker load -i <file.tar> | Loads an image from a tar archive. |
๐ก 3. Docker Container Management
| Command | Description |
docker ps | Lists all running containers. |
docker ps -a | Lists all containers (running + stopped). |
docker run <image> | Runs a new container. |
docker run -it <image> | Runs a container in interactive mode with terminal. |
docker run -d <image> | Runs a container in detached (background) mode. |
docker run -d -p 80:80 --name <container_name> <image_name>:<tag> | Runs a container, maps port 80, names it, and sets tag. |
docker start <container_name> | Starts a stopped container. |
docker stop <container_name> | Stops a running container. |
docker kill <container_name> | Forcefully kills a running container. |
docker restart <container_name> | Restarts a container. |
docker rename <old_name> <new_name> | Renames an existing container. |
docker rm <container_name> | Removes a stopped container. |
docker container prune | Removes all stopped containers. |
docker rmi -f $(docker images -aq) | forcefully Deletes all the images |
docker images -aq | Lists IDโs of all the images |
๐ฃ 4. Logs, Monitoring & Inspection
| Command | Description |
docker logs <container_name> | Displays logs of a container. |
docker logs -f <container_name> | Follows logs in real-time. |
docker top <container_name> | Shows processes running inside a container. |
docker inspect <id_or_name> | Displays JSON config/details for container or image. |
docker container inspect <container_name> | Detailed inspection specifically for containers. |
docker stats | Shows CPU, memory, I/O usage of running containers. |
docker exec -it <container_name> bash | Opens a bash shell inside a running container. |
๐ด 5. Networking, Volumes & Advanced
| Command | Description |
docker network ls | Lists all Docker networks. |
docker network create <name> | Creates a custom network. |
docker network connect <network> <container> | Connects a container to a network. |
docker network inspect <network> | Shows details about a network. |
docker volume ls | Lists all Docker volumes. |
docker volume create <name> | Creates a new volume. |
docker compose up -d | Starts services defined in a docker-compose.yml. |
docker compose down | Stops & removes containers, networks, volumes from compose. |
docker export <container_id> -o <file.tar> | Exports a container filesystem as tar. |
docker import <file.tar> | Imports a container filesystem from tar. |



