What is a Docker Image?
A Docker Image is a read-only template used to create Docker containers. It contains the application code, runtime, libraries, environment variables, and configuration files needed to run an application.
Think of an image like a class in OOP — you define it once and create multiple containers (objects) from it.
Docker Image Commands
| Command | Description |
|---|---|
docker images |
List all local images |
docker pull <image> |
Download image from Docker Hub |
docker build -t <name> . |
Build image from Dockerfile |
docker rmi <image> |
Remove an image |
docker tag <image> <new-name> |
Tag an image with a new name |
docker push <image> |
Push image to Docker Hub |
docker inspect <image> |
View detailed image metadata |
Pulling an Image from Docker Hub
# Pull latest nginx image
docker pull nginx
# Pull specific version
docker pull nginx:1.25
# Pull ubuntu image
docker pull ubuntu:22.04
Listing Local Images
docker images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 61395b4c586d 2 weeks ago 187MB
ubuntu 22.04 3b418d7b466a 4 weeks ago 77.8MBBuild an Image from Dockerfile
Create a simple Dockerfile:
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y curl
CMD ["bash"]
Build the image:
# Build image with tag name myapp
docker build -t myapp .
Verify the image was created:
docker images
Tagging an Image
# Tag image for Docker Hub
docker tag myapp yourusername/myapp:v1.0
Removing an Image
# Remove by image name
docker rmi nginx
# Remove by image ID
docker rmi 61395b4c586d
# Force remove even if container is using it
docker rmi -f nginx
Image Layers
Docker images are built in layers. Each instruction in a Dockerfile creates a new layer. Layers are cached, so rebuilding is fast when only a few layers change.
# View image history and layers
docker history nginxSummary
- A Docker image is a read-only blueprint for creating containers.
- Use
docker pullto download images anddocker buildto create your own. - Images are made of layers — cached for faster builds.
- Use
docker rmito remove unused images and free disk space.
Your Feedback
Help us improve by sharing your thoughts
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
