Kritim Yantra
Apr 24, 2025
Docker is a powerful platform that allows developers to build, ship, and run applications in lightweight, portable containers. At the heart of Docker lies the concept of Docker Images, which are the blueprints for creating containers.
In this blog, we’ll explore:
A Docker Image is a read-only template that contains instructions for creating a Docker container. It includes:
Images are built using a Dockerfile, which defines all the necessary steps to assemble the image.
ubuntu
, alpine
, python:3.9
).nginx:latest
, python:3.9-slim
).docker pull
– Download an Image from a RegistryDownloads an image from Docker Hub (or another registry) to your local machine.
Syntax:
docker pull [OPTIONS] IMAGE_NAME[:TAG]
Example:
docker pull nginx:latest
Explanation:
nginx:latest
→ Downloads the latest version of the Nginx image.latest
by default.docker images
/ docker image ls
– List Downloaded ImagesDisplays all locally stored Docker images with various filtering and formatting options.
Syntax:
docker images [OPTIONS] [REPOSITORY[:TAG]]
# OR
docker image ls [OPTIONS] [REPOSITORY[:TAG]]
Example:
docker images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest abc12345678 2 weeks ago 133MB
ubuntu 20.04 def98765432 3 weeks ago 72.8MB
--filter
(-f
) → Filter images based on criteria:
reference="nginx*"
→ Shows images with names starting with "nginx".before=nginx:latest
→ Lists images created before nginx:latest
.since=ubuntu:20.04
→ Lists images created after ubuntu:20.04
.dangling=true
→ Shows untagged (dangling) images.label=version=1.0
→ Filters images with a specific label.--all
(-a
) → Shows all images (including intermediate layers).
--no-trunc
→ Displays full image IDs (without truncation).
--quiet
(-q
) → Only shows image IDs (useful for scripting).
--digests
→ Displays SHA-256 digests (for verification).
Examples:
# Show only dangling (untagged) images
docker images --filter dangling=true
# Display images created before a specific image
docker images --filter before=nginx:latest
# Show images matching a reference pattern
docker images --filter reference="nginx*"
# List only image IDs (useful for automation)
docker images -q
docker build
– Create an Image from a DockerfileBuilds a new Docker image using instructions from a Dockerfile
.
Syntax:
docker build [OPTIONS] PATH
Example:
docker build -t my-app:1.0 .
Explanation:
-t my-app:1.0
→ Tags the image with a name (my-app
) and version (1.0
)..
→ The build context (current directory where the Dockerfile
is located).docker rmi
– Remove an ImageDeletes a locally stored Docker image.
Syntax:
docker rmi [OPTIONS] IMAGE [IMAGE...]
Example:
docker rmi nginx:latest
Explanation:
docker tag
– Tag an ImageAssigns a new tag to an existing image (useful for versioning).
Syntax:
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
Example:
docker tag my-app:1.0 my-app:latest
Explanation:
my-app:latest
) pointing to the same image as my-app:1.0
.docker push
– Upload an Image to a RegistryUploads a locally built image to a registry (e.g., Docker Hub).
Syntax:
docker push [OPTIONS] NAME[:TAG]
Example:
docker push my-app:1.0
Explanation:
docker login
).docker save
– Export an Image to a FileSaves an image as a .tar
file for sharing or backup.
Syntax:
docker save -o FILENAME.tar IMAGE_NAME
Example:
docker save -o nginx.tar nginx:latest
Explanation:
.tar
file of the image.docker load
– Import an Image from a FileLoads an image from a .tar
file.
Syntax:
docker load -i FILENAME.tar
Example:
docker load -i nginx.tar
Explanation:
docker save
.latest
in production; use versioned tags (python:3.9
).alpine
.docker image prune
to clean up.docker scan
to check for security issues.Docker images are the foundation of containerized applications. Understanding how to pull, build, tag, and manage them is crucial for efficient Docker usage.
Command | Purpose |
---|---|
docker pull |
Download an image |
docker images / docker image ls |
List local images (with filtering) |
docker build |
Build an image from a Dockerfile |
docker rmi |
Remove an image |
docker tag |
Assign a new tag |
docker push |
Upload to a registry |
docker save |
Export as .tar |
docker load |
Import from .tar |
By mastering these commands and filtering options, you'll be able to efficiently manage Docker images in your projects! 🚀
Happy Dockering! 🐳
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google