A Docker image is a lightweight, standalone, and executable software package that includes everything needed to run an application: code, runtime, system tools, libraries, and settings.
A Docker image is a read-only template that contains instructions for creating a container. It serves as a snapshot of an application and its environment at a specific point in time. Images are built from a Dockerfile, which defines the steps to assemble the image. Once built, images are stored in a registry like Docker Hub and can be shared, versioned, and reused across different environments. When you run an image using the docker run command, Docker creates a writable container layer on top of the image, allowing applications to run while preserving the underlying immutable image .
Images are composed of multiple layers stacked on top of each other, forming a union filesystem. Each layer represents a set of filesystem changes—adding a file, modifying a file, or deleting a file. These layers are cached and reused across different images, making image storage and distribution highly efficient. For example, if multiple images are based on the same Ubuntu base layer, that layer is downloaded only once and shared among all images. This layering mechanism is what makes Docker images lightweight and fast to transfer .
Each instruction in a Dockerfile creates a new layer in the final image. The FROM instruction sets the base image, which itself is composed of layers. RUN commands execute commands in a temporary container and capture the filesystem changes as a new layer. COPY and ADD instructions also create layers containing the files you specify. These layers are cached by Docker, so if you rebuild the image and only the later instructions change, Docker can reuse the cached layers from earlier steps, dramatically speeding up rebuilds .
Immutability: Images are read-only and cannot be changed once built. Any modifications create a new image with a new layer on top .
Layering: Images consist of stacked layers that build upon each other, enabling reuse and efficient storage .
Portability: Images contain everything needed to run the application, ensuring consistent behavior across different environments .
Versioning: Images can be tagged with version numbers (e.g., my-app:1.0, my-app:latest) for release management .
Registry storage: Images are stored in registries like Docker Hub, private registries, or cloud repositories for distribution .