-
Check Docker Version:
docker --version
-
Show System-Wide Docker Information:
docker info
-
List Running Containers:
docker ps
-
List All Containers (Running and Stopped):
docker ps -a
-
Restart a Stopped Container:
docker start <container_id>
-
Stop a Running Container:
docker stop <container_id>
-
Access a Running Container (Interactive Mode):
docker exec -it <container_id> bash
-
Remove a Specific Container:
docker rm <container_id>
-
Run a Container in Detached Mode:
docker run -d <image_name>
-
Remove All Stopped Containers, Unused Images, and Volumes:
docker system prune -a --volumes
-
Run a Container with Resource Limits:
docker run --memory="512m" --cpus="1" <image_name>
-
List All Docker Images:
docker images
-
Pull a Specific Image from Docker Hub:
docker pull <image_name>:<tag>
Example:
docker pull ubuntu:20.04
-
Export an Image to a
.tar
File:docker save -o my_image.tar <image_name>:<tag>
-
Load an Image from a
.tar
File:docker load -i my_image.tar
-
Tag an Image:
docker tag <image_id> <new_image_name>:<tag>
-
Push an Image to a Docker Registry:
docker push <image_name>:<tag>
-
Remove a Specific Image:
docker rmi <image_id>
-
Remove All Unused Images:
docker image prune -a
-
Save a Docker Image to a
.tar
File:docker save -o my_image.tar <image_name>:<tag>
-
Load a Docker Image from a
.tar
File:docker load -i my_image.tar
-
Export a Container to a
.tar
File:docker export -o my_container.tar <container_id>
-
Import a Container's Filesystem from a
.tar
File:cat my_container.tar | docker import - my_container
-
List All Volumes:
docker volume ls
-
Create a Named Volume:
docker volume create <volume_name>
-
Inspect a Volume:
docker volume inspect <volume_name>
-
Remove a Volume:
docker volume rm <volume_name>
-
List Docker Networks:
docker network ls
-
Create a Docker Network:
docker network create <network_name>
-
Connect a Container to a Network:
docker network connect <network_name> <container_id>
-
Disconnect a Container from a Network:
docker network disconnect <network_name> <container_id>
-
View Container Logs:
docker logs <container_id>
-
Inspect Container Details:
docker inspect <container_id>
-
Check Resource Usage of Containers:
docker stats
-
Check Disk Usage of Docker Resources:
docker system df
-
Start Services Defined in
docker-compose.yml
:docker-compose up
-
Stop Services:
docker-compose down
-
Rebuild and Start Services:
docker-compose up --build
-
Check Logs of Services:
docker-compose logs
-
Stop All Running Containers:
docker stop $(docker ps -q)
-
Remove All Containers (Stopped or Running):
docker rm $(docker ps -aq)
-
Remove All Unused Images:
docker image prune -a
-
Remove All Docker Resources (DANGEROUS):
docker system prune -a --volumes