Frequently Used Docker Commands
A collection of frequently used Docker commands
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
Command | Stopped Containers | Unused Networks | Dangling Images | Unused Images | Unused Anonymous Volumes | Unused Named Volumes |
---|---|---|---|---|---|---|
docker system \ prune | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
docker system \ prune --volumes | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ |
docker system \ prune -a | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
docker system \ prune -a --volumes | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
docker volume \ prune | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ |
docker volume \ prune -a | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ |
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 | Stop services |
docker compose down -v | Stop services and remove volumes |
docker compose ls | List all projects |
docker compose up --build
rebuilds the images
This post is licensed under CC BY 4.0 by the author.