Image management with Docker #
Docker images are the foundation of containerization. This section introduces commands to pull, list, and remove images, enabling you to manage the base templates used to create containers.
Start by pulling, i.e., downloading into your local disk, a PostgreSQL image:
docker pull postgres:15Image tags are used to identify specific versions of an image. For example, postgres:latest refers to the most recent version of the PostgreSQL image, while postgres:15 refers to a specific release. Tags help you manage and deploy precise versions of images, ensuring consistency and reliability across different environments.
Show available local images:
docker imagesNow download a different image with a more recent version of PostgreSQL:
docker pull postgres:17If you run docker images again, you should have (at least) two images available. Optionally, you can now delete the image you do not plan to use, say postgres:15:
docker rmi postgres:15When you use docker pull, Docker downloads the image in layers. Each layer represents a specific change to the filesystem, such as installing a package or adding an application. This layered approach allows for efficient storage and faster downloads, as only the layers that are missing or updated are transferred, reducing bandwidth usage and improving performance.