🐳 Docker Command Cheat Sheet
🔢 Basic Docker Commands

1 .docker --version
Use Case: Verify Docker installation and version.
Example:
docker --version
- Output:
Docker version 24.0.5, build ced0996
2. docker info
Use Case: Display system-wide information about Docker installation.
Example:
docker info
- Output:
Containers: 3
Running: 1
Paused: 0
Stopped: 2
Images: 10
…
3. docker help
Use Case: List available Docker commands and options.
Example:
docker help
- Output:
Usage: docker [OPTIONS] COMMAND
…

🚀 Container Management
1. docker ps
Use Case: List running containers.
Example:
docker ps
- Output:
CONTAINER ID IMAGE COMMAND STATUS NAMES
abc123 nginx … Up 5s mynginx
2.docker ps -a
Use Case: List all containers, including stopped ones.
Example:
docker ps - a
- Output:
CONTAINER ID IMAGE COMMAND STATUS NAMES
abc123 nginx … Exited (0) 2 minutes ago mynginx
3. docker stop < container_id >
Use Case: Stop a running container.
Example:
docker stop abc123
- Output:
abc123
4. docker start < container_id >
Use Case: Start a previously stopped container.
Example:
docker start abc123
- Output:
abc123
5. docker restart < container_id >
Use Case: Restart a container (stop and start).
Example:
docker restart abc123
- Output:
abc123
6. docker rm < container_id >
Use Case: Remove a stopped container from the system.
Example:
docker rm abc123
- Output:
abc123
7. docker logs < container_id >
Use Case: View logs for a container.
Example:
docker logs abc123
- Output:
Starting nginx...
Ready to serve requests
8. docker exec -it < container_id > bash
Use Case: Access the shell of a running container.
Example:
docker exec -it abc123 bash
- Output:
root@abc123:/#
🌀 Image Management

1. docker images
Use Case: List all Docker images available locally.
Example:
docker images
- Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest abcdef123456 3 days ago 133MB
2. docker pull < image_name >
Use Case: Download an image from Docker Hub.
Example:
docker pull nginx
- Output:
Using default tag: latest
latest: Pulling from library/nginx
…
Digest: sha256:…
Status: Downloaded newer image for nginx:latest
3. docker rmi < image_name >
Use Case: Remove a local Docker image.
Example:
docker rmi nginx
- Output:
Untagged: nginx:latest
Deleted: sha256:…
4. docker build - t < image_name > .
Use Case: Build a Docker image from a Dockerfile.
Example:
docker build -t myapp .
- Output:
Successfully built abcdef123456
Successfully tagged myapp:latest

🛠️ Running Containers
1. docker run < image_name >
Use Case: Run a container from an image.
Example:
docker run nginx
- Output:
... (nginx process logs)
2. docker run -d < image_name >
Use Case: Run a container in the background (detached mode ).
Example:
docker run -d nginx
- Output:
abc123456789...
3. docker run --name < name > < image >
Use Case: Assign a name to the container
Example:
docker run --name mynginx nginx
- Output:
... (container output)
4. docker run -p 8080:80 < image >
Use Case: Expose a container port to the host.
Example:
docker run -p 8080:80 nginx
- Output:
... (nginx running and accessible at localhost:8080)
5. docker run -v /host/path:/container/path < image >
Use Case: Mount host directory into the container.
Example:
docker run -v /tmp:/data nginx
- Output:
... (container starts and has access to /data)
6. docker run --rm < image >
Use Case: Automatically remove the container once it stops.
Example:
docker run --rm hello-world
- Output:
Hello from Docker!
...
🌐 Networking

1. docker network ls
Use Case: List all Docker networks.
Example:
docker network ls
- Output:
NETWORK ID NAME DRIVER SCOPE
abc123 bridge bridge local
. . .
2.docker network create < network_name >
Use Case: Create a new custom network.
Example:
docker network create mynet
- Output:
mynet
3. docker network inspect < network_name >
Use Case: Inspect detailed information about a network.
Example:
docker network inspect mynet
- Output:
[
{
“Name”: “mynet”,
“Id”: “…”,
“Containers”: {},
…
}
]
4. docker network connect < network_name > < container_name >
Use Case: Connect a container to a network.
Example:
docker network connect mynet mynginx
- Output:
(no output if successful)
5. docker network disconnect <network_name> <container_name>
Use Case: Disconnect a container from a network.
Example:
docker network disconnect mynet mynginx
- Output:
(no output if successful)

📁 Volumes & Storage
1. docker volume ls
Use Case: List all docker volumes
Example:
docker volume ls
- Output:
DRIVER VOLUME NAME
local myvolume
2. docker volume create < volume_name >
Use Case: Create a new volume
Example:
docker volume create myvolume
- Output:
myvolume
3. docker volume inspect < volume_name >
Use Case: View detailed info about a volume.
Example:
docker volume inspect myvolume
- Output:
[
{
“Name”: “myvolume”,
“Driver”: “local”,
…
}
]
4. docker volume rm < volume_name >
Use Case: Delete a Volume
Example:
docker volume rm myvolume
- Output:
myvolume
📄 Docker Compose

1. docker-compose up
- Use Case: Start services defined in a
docker-compose.yml
. Example:
docker-compose up
- Output:
Starting myapp … done
…
2. docker-compose up -d
- Use Case:Start services in detached mode.
Example:
docker-compose up -d
- Output:
Creating network “myapp_default” with the default driver
Creating myapp … done
3. docker-compose down
- Use Case: Stop and remove all services and resources created by Compose.
Example:
docker-compose down
- Output:
Stopping myapp … done
Removing myapp … done
Removing network myapp_default

🏰 Docker System Cleanup
1. docker system prune
- Use Case: Remove all unused data (containers, networks, images).
Example:
docker system prune
- Output:
Deleted Containers:
…
Total reclaimed space: 200MB
2. docker image prune
- Use Case: Remove unused images.
Example:
docker image prune
- Output:
Deleted Images:
…
Total reclaimed space: 150MB
3. docker container prune
- Use Case: Remove stopped containers.
Example:
docker container prune
- Output:
Deleted Containers:
…
Total reclaimed space: 50MB
🛠️ Docker Registry & Hub

1. docker login
- Use Case: Authenticate with Docker Hub or a private registry.
Example:
docker login
- Output:
Login Succeeded
2. docker logout
- Use Case: Logout from the Docker registry.
Example:
docker logout
- Output:
Removing login credentials for https://index.docker.io/v1/
3. docker tag < image_name > < registry >/< repo >:< tag >
- Use Case: Tag an image before pushing to a registry.
Example:
docker tag myapp myregistry/myapp:latest
- Output:
(no output if successful)
4. docker push < registry >/< repo >:< tag >
- Use Case: Upload an image to a registry.
Example:
docker push myregistry/myapp:latest
- Output:
The push refers to repository [myregistry/myapp]
…
latest: pushed
5. docker pull < registry >/< repo >:< tag >
- Use Case: Download an image from a registry.
Example:
docker pull myregistry/myapp:latest
- Output:
latest: Pulling from myapp
…
Digest: sha256:…
Status: Downloaded newer image
6. docker search < image_name >
- Use Case: Search for images on Docker Hub.
Example:
docker search nginx
- Output:
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of 15000+ [OK]
DevOps with multi cloud Training
Take your DevOps skills to the next level with our Multi Cloud training! Gain hands-on experience, real-world project exposure, and industry-recognized expertise. Enroll today and step into a high-demand career