Frequently Used Docker Commands
A collection of frequently used Docker commands
docker version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Client:
Version: 27.5.1-rd
API version: 1.47
Go version: go1.22.11
Git commit: 0c97515
Built: Thu Jan 23 18:12:38 2025
OS/Arch: darwin/arm64
Context: desktop-linux
Server: Docker Desktop 4.42.0 (195023)
Engine:
Version: 28.2.2
API version: 1.50 (minimum version 1.24)
Go version: go1.24.3
Git commit: 45873be
Built: Fri May 30 12:07:27 2025
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.7.27
GitCommit: 05044ec0a9a75232cad458027ca83437aae3f4da
runc:
Version: 1.2.5
GitCommit: v1.2.5-0-g59923ef
docker-init:
Version: 0.19.0
GitCommit: de40ad0
1. Image & Container Management
Command | Description |
---|---|
docker pull <image-name> | Pull image from registry |
docker create --name <container-name> <image-name> | Create container without running it |
docker run -it --name <container-name> <image-name> | Create and Run container interactively |
docker exec -it <container-name> <command> | Execute command in running container |
docker ps -a | List all containers |
docker start <container-name> | Start container |
docker stop <container-name> | Stop container |
docker logs <container-name> | Show logs |
docker rm <container-name> | Remove container |
docker rmi <image-name> | Remove image |
2. Volume Management
Command | Description |
---|---|
docker volume ls | List volumes |
docker volume create <volume-name> | Create volume |
docker volume rm <volume-name> | Remove volume |
docker run -v <volume-name>:<container-path> <image-name> | Mount volume to container |
docker run -v <host-path>:<container-path> <image-name> | Mount host path to container |
Press
Ctrl + p + q
to exit the terminal without stopping the container
3. System Management
Command | Description |
---|---|
docker system df -v | Show Docker daemon disk usage |
docker system prune | Remove unused data |
4. Docker Prune Commands Comparison
The commands below prune the checked column items
Command | Stopped Containers | Unused Networks | Build Cache (Unused) | Build Cache (All) | Dangling Images | All Unused Images | Unused Anonymous Volumes | Unused Named Volumes |
---|---|---|---|---|---|---|---|---|
docker system \ prune | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
docker system \ prune -a | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ |
docker system \ prune --volumes | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ✅ | ❌ |
docker system \ prune -a --volumes | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ |
docker container \ prune | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
docker image \ prune | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
docker image \ prune -a | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ |
docker volume \ prune | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ |
docker volume \ prune -a | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ |
docker builder \ prune | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
docker builder \ prune -a | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
Stopped Containers: These are containers that are no longer running but still exist on your Docker system. They result from docker run commands followed by a stop or exit.
Unused Networks: These are networks** not currently connected to any running containers or services**. Networks can often persist even after the containers using them are removed.
Build Cache (Unused): These are intermediate layers created during the Docker image build process. While they speed up future builds, unreferenced or unnecessary cache layers can accumulate. Commands like docker system prune or docker builder prune (without -a) target these.
Build Cache (All): This refers to the forcible deletion of all build cache, including actively used or recently accessed cache layers. The
docker builder prune -a
command performs this comprehensive cleanup. Be aware that this can significantly increase your next build time.
Dangling Images: These are images that have no tag (e.g., latest, v1.0) and are not referenced by any containers. They often appear when you rebuild an image, causing the older version to lose its tag.
All Unused Images: This includes dangling images, plus any other images that have tags but are not currently used by any running containers. Commands like
docker system prune -a
ordocker image prune -a
target this broader category of images.
Unused Anonymous Volumes: These are volumes created without a specific name (e.g., via
docker run -v /path/in/container
) that are no longer associated with any containers. This means that the associated containers have already been removed.
Unused Named Volumes: These are named volumes (e.g., created with
docker volume create my-volume
) that are no longer associated with any containers. This means that the associated containers have already been removed.
Orphaned Containers: These are stopped containers that exist but cannot be restarted because their associated images have been removed. This typically happens when you run
docker image prune -a
while having stopped containers. These containers are essentially useless since they cannot be started without their images.
5. Examples
1
2
# Pull Ubuntu image
docker image pull ubuntu:24.04
1
2
# Run Ubuntu container
docker container run -it -v ./test-volume:/home/ubuntu --name ubuntu-test ubuntu:24.04
1
2
# Execute bash in container
docker container exec -it ubuntu-test /bin/bash
6. Docker Compose Commands
Command | Description |
---|---|
docker compose up | Apply changed compose.yml and start services |
docker compose up <service-name> | Start a specific service |
docker compose down | Remove containers and networks created by up |
docker compose down -v | Remove containers, networks, and volumes created by up |
docker compose ls | List all projects |
docker compose up --build
rebuilds the images