Working with Images
A comprehensive developer cheatsheet covering Docker image management, featuring essential CLI commands and operational workflows for pulling, searching, inspecting, tagging, and removing Docker images.
Understanding Docker Images
What is a Docker Image?
A Docker image is a lightweight, standalone, executable package that includes everything needed to run a piece of software: code, runtime, system tools, libraries, and settings.
Image Naming Convention
[registry/][username/]image[:tag]| Part | Example | Purpose |
|---|---|---|
| Registry | docker.io | Registry hostname (default: Docker Hub) |
| Username | nginx | Owner of the image |
| Image | nginx | Image name |
| Tag | latest, 1.25, alpine | Version or variant |
Examples:
nginx:latest— Official Nginx image, latest tagnginx:1.25— Nginx version 1.25alpine:3.19— Alpine Linux version 3.19myuser/myapp:v1.0— Custom image from myuser
docker pull — Download an Image
Downloads (pulls) an image from a registry.
Basic Usage
$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete
9e1c7197b2c1: Pull complete
5b3bd6d9616b: Pull complete
Digest: sha256:abc123...
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latestCommon Flags
| Flag | Purpose |
|---|---|
-a, --all-tags | Download all tagged images |
--platform | Specify platform (linux/amd64, linux/arm64) |
-q, --quiet | Suppress verbose output |
Examples
Pull specific version:
$ docker pull nginx:1.25Pull from a specific registry:
$ docker pull myregistry.com/myapp:v1.0Pull all tags:
$ docker pull -a nginxPull for a specific platform:
$ docker pull --platform linux/arm64 nginxPull with quiet output:
$ docker pull -q nginxdocker images — List Local Images
Lists all locally stored Docker images.
Basic Usage
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest abc123def456 2 days ago 187MB
alpine 3.19 456def789abc 5 days ago 7.05MB
ubuntu 22.04 789abc123def 2 weeks ago 77.8MB
myapp v1.0 def456789abc 3 weeks ago 245MBCommon Flags
| Flag | Purpose |
|---|---|
-a, --all | Show all images (including intermediate) |
-q, --quiet | Show only image IDs |
--digests | Show digests |
--filter | Filter results (e.g., --filter "dangling=true") |
--format | Format output using Go template |
Examples
Show only image IDs:
$ docker images -q
abc123def456
456def789abc
789abc123defShow with digests:
$ docker images --digests
REPOSITORY TAG DIGEST IMAGE ID SIZE
nginx latest sha256:abc123... abc123def456 187MBFilter dangling images:
$ docker images --filter "dangling=true"Filter by reference:
$ docker images --filter "reference=nginx:*"Format output as table:
$ docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"Format as JSON (using Go template):
$ docker images --format '{{json .}}'docker search — Search Docker Hub
Searches Docker Hub for images.
Basic Usage
$ docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 18500 [OK]
nginx/nginx-ingress NGINX Ingress Controller 150
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGINX... 50
linuxserver/nginx Nginx is a web server... 45Common Flags
| Flag | Purpose |
|---|---|
--limit N | Limit number of results (max 100) |
--filter | Filter results (stars, is-official, is-automated) |
--format | Format output using Go template |
Examples
Search with star filter:
$ docker search nginx --filter stars=100Search only official images:
$ docker search nginx --filter is-official=trueLimit results:
$ docker search nginx --limit 5docker history — Show Image History
Shows the layer history of an image.
Basic Usage
$ docker history nginx
IMAGE CREATED CREATED BY SIZE
abc123def456 2 days ago CMD ["nginx" "-g" "daemon off;"] 0B
def456789abc 2 days ago STOPSIGNAL SIGQUIT 0B
789abc123def 2 days ago EXPOSE map[80/tcp:{}] 0B
...Common Flags
| Flag | Purpose |
|---|---|
--no-trunc | Don't truncate output |
-q, --quiet | Show only image IDs |
--format | Format output |
Examples
Show full command (no truncation):
$ docker history --no-trunc nginxShow only image IDs:
$ docker history -q nginxdocker inspect — Show Image Details
Shows detailed information about an image in JSON format.
Basic Usage
$ docker inspect nginx
[
{
"Id": "sha256:abc123def456...",
"RepoTags": [
"nginx:latest"
],
"RepoDigests": [
"nginx@sha256:abc123..."
],
"Parent": "",
"Comment": "",
"Created": "2026-01-15T10:30:15.123456789Z",
"Container": "",
"ContainerConfig": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.25.3"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"nginx\" \"-g\" \"daemon off;\"]"
],
"Image": "",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
}
},
"DockerVersion": "20.10.23",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.25.3"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"Image": "",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 187123456,
"VirtualSize": 187123456
}
]Common Flags
| Flag | Purpose |
|---|---|
-f, --format | Format output using Go template |
Examples
Get specific field (e.g., ExposedPorts):
$ docker inspect nginx --format='{{.Config.ExposedPorts}}'
map[80/tcp:{}]Get environment variables:
$ docker inspect nginx --format='{{.Config.Env}}'
[PATH=/usr/local/sbin:... NGINX_VERSION=1.25.3]Get image size:
$ docker inspect nginx --format='{{.Size}}'
187123456Get specific field with jq:
$ docker inspect nginx | jq '.[0].Config.Cmd'docker rmi — Remove an Image
Removes one or more images.
Basic Usage
$ docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:abc123...
Deleted: sha256:abc123def456...
Deleted: sha256:def456789abc...Common Flags
| Flag | Purpose |
|---|---|
-f, --force | Force removal (even if running) |
--no-prune | Don't delete untagged parents |
Examples
Remove multiple images:
$ docker rmi nginx alpine ubuntuRemove by image ID:
$ docker rmi abc123def456Force remove:
$ docker rmi -f nginxRemove all unused images:
$ docker rmi $(docker images -q)Remove dangling images:
$ docker rmi $(docker images --filter "dangling=true" -q)docker tag — Tag an Image
Creates a new tag for an existing image.
Basic Usage
$ docker tag nginx:latest myregistry.com/mynginx:v1.0Syntax
$ docker tag [SOURCE] [TARGET]Examples
Tag for Docker Hub:
$ docker tag nginx:latest myusername/nginx:latestTag for private registry:
$ docker tag nginx:latest myregistry.com/myapp:1.0Tag with multiple tags:
$ docker tag nginx:latest myapp:latest
$ docker tag nginx:latest myapp:v1.0Tag for versioning:
$ docker tag myapp:latest myapp:1.0.0
$ docker tag myapp:latest myapp:1.0
$ docker tag myapp:latest myapp:1Quick Reference — Most Used Commands
| Task | Command |
|---|---|
| Pull an image | docker pull nginx |
| Pull specific version | docker pull nginx:1.25 |
| List images | docker images |
| List image IDs only | docker images -q |
| Search Docker Hub | docker search nginx |
| Show image history | docker history nginx |
| Inspect image | docker inspect nginx |
| Get specific field | docker inspect nginx --format='{{.Size}}' |
| Remove an image | docker rmi nginx |
| Remove all images | docker rmi $(docker images -q) |
| Tag an image | docker tag nginx:latest myapp:v1.0 |
Pro Tips
-
Always use specific tags — avoid
:latestin production. -
Clean up unused images regularly:
bashdocker rmi $(docker images --filter "dangling=true" -q) -
Check image size before pulling:
bashdocker search nginx --limit 1 -
Use
--platformfor multi-architecture builds. -
Inspect images to understand what's inside.
-
Use
docker images --digeststo see image hashes. -
Tag before pushing to registry.
-
Pull images with
-qin CI/CD to reduce logs.