Image Management
You’ll Use Daily - Your Docker Toolkit
Imagine you’re running a library. Books (images) need to be cataloged, tagged, stored, borrowed, and sometimes discarded. Without proper management, the library becomes chaotic. Similarly, Docker images must be managed carefully to avoid clutter, ensure consistency, and enable smooth collaboration across teams.
Image Foundations
1. Tagging Images
- Purpose: Assign meaningful names and versions to images.
- Format:
repository:tag(e.g.,myapp:1.0). - Default Tag: If no tag is specified, Docker uses
latest.
docker tag hello-image myrepo/hello:1.0
2. Pushing Images to Registries
- Registries: Central repositories for storing and sharing images.
- Docker Hub: Default public registry.
- Private Registries: Enterprises use them for internal distribution.
- Push Workflow:
- Tag the image with registry/repo name.
- Log in (
docker login).
Push the image:
docker push myrepo/hello:1.0
3. Pulling Images from Registries
- Purpose: Download images to your local system.
- Caching: Once pulled, images are stored locally for reuse.
docker pull ubuntu:20.04
4. Listing and Inspecting Images
- Provides details about layers, size, and configuration.
Inspect Metadata:
docker inspect nginx
List Images:
docker images
5. Cleaning Up Images
Remove All Unused Images:
docker system prune -a
Remove Dangling Images (unused layers):
docker image prune
Remove Specific Image:
docker rmi image_id
Things to Remember
- Tagging ensures clarity and version control.
- Pushing/pulling enables collaboration across environments.
- Cleaning up prevents disk space issues and keeps systems efficient.
Hands‑On Lab
Step 1: Tag an Image
docker tag hello-image mydockerhub/hello:latest
Step 2: Push to Docker Hub
docker login
docker push mydockerhub/hello:latest
Step 3: Pull the Image on Another Machine
docker pull mydockerhub/hello:latest
Step 4: Clean Up
docker rmi hello-image
docker image prune
Practice Exercise
- Create a custom image using a Dockerfile.
- Tag it with two different versions (
v1,v2). - Push both versions to Docker Hub.
- Pull them back and compare differences.
- Clean up unused images and note the freed disk space.
Visual Learning Model
Local Image → Tag → Push → Registry → Pull → Local Image → Container
The Hackers Notebook
Image management is about organization and collaboration. By tagging, pushing, pulling, and cleaning up images, developers ensure smooth workflows, efficient storage, and reliable deployments. Mastering image management is key to working in team environments and scaling applications.
