Check Docker Version
Display Docker version information.
docker --version
Detailed version and system info:
docker version
docker info
Run a Container
Run a container from an image.
docker run <image-name>
Run in detached mode:
docker run -d <image-name>
Run with custom name:
docker run --name my-container <image-name>
Run with port mapping:
docker run -p 8080:80 nginx
List Containers
Show running containers.
docker ps
Show all containers including stopped:
docker ps -a
Show only container IDs:
docker ps -q
List Images
Display all local images.
docker images
Alternative command:
docker image ls
Pull an Image
Download image from Docker Hub.
docker pull <image-name>
Pull specific version:
docker pull ubuntu:20.04
Build an Image
Build image from Dockerfile.
docker build -t <image-name> .
Build with specific Dockerfile:
docker build -f Dockerfile.dev -t my-image .
Execute Commands in Container
Run command in running container.
docker exec <container-id> <command>
Interactive shell access:
docker exec -it <container-id> /bin/bash
View Container Logs
Display container logs.
docker logs <container-id>
Follow log output:
docker logs -f <container-id>
Show last N lines:
docker logs --tail 100 <container-id>
Stop a Container
Gracefully stop running container.
docker stop <container-id>
Force stop:
docker kill <container-id>
Remove Container
Delete stopped container.
docker rm <container-id>
Force remove running container:
docker rm -f <container-id>
Remove Image
Delete image from local system.
docker rmi <image-id>
Force remove:
docker rmi -f <image-id>
Search Images
Search Docker Hub for images.
docker search <term>
Inspect Container
View detailed container information.
docker inspect <container-id>
Container Stats
Display resource usage statistics.
docker stats
Stats for specific container:
docker stats <container-id>