Master Docker Images: From Basics to Advanced Management
This article provides a comprehensive guide to Docker images, covering core concepts, image sources, essential commands for searching, pulling, tagging, inspecting, pruning, exporting, importing, and pushing images, along with practical examples and tips for effective container image management.
Docker Series Guide
Learning Docker requires mastering three core concepts: image, container, and repository.
Today we focus on the fundamentals of Docker images.
Docker Image Overview
1. What Is an Image?
A Docker image is a read‑only template. For VM administrators it is similar to a VM template, and for developers it can be thought of as a class.
In short, a Docker image is a minimal operating system without a kernel that can run applications.
For example, an image may contain a basic Ubuntu environment with Nginx installed, often called an Nginx image.
2. Where Do Images Come From?
Docker Hubis the public registry maintained by Docker, containing many images. The Docker client defaults to downloading images from this registry.
Downloading the nginx image
Image Management Commands
Below are the key Docker commands for handling images.
1. Search Images
Docker search syntax
# Example: search for MySQL‑related images
docker search mysql2. Pull Images
Docker pull syntax
Typically an image is identified by name + tag. For example, to pull the Ubuntu 18.04 image: docker pull ubuntu:18.04 If no tag is specified, Docker uses the latest tag by default.
Do not assume latest means “newest”; it is just a convention and does not trigger automatic updates.
# List images for repository web_repo
docker images web_repoTagging can change which tag points to which image ID.
3. View Images
1) List local images
Fields explained: REPOSITORY – source repository (e.g., ubuntu) TAG – version label IMAGE ID – unique identifier CREATED – creation time SIZE – image size
2) Inspect image details
The command returns JSON with author, architecture, layer digests, etc. Use -f to filter, e.g., to get the creation time.
3) View image history
Docker images consist of multiple layers. Use docker history to list each layer’s creation command.
Use --no-trunc to avoid truncating long commands.
4. Tag Images
Tag syntax:
docker tag ubuntu:latest myubuntu:v15. Delete Images
1) Delete by tag
# docker rmi myubuntu:v1
Untagged: myubuntu:v1Removing a tag does not delete the underlying image if other tags exist.
2) Delete by image ID
# docker rmi 005d2078bdfaIf an image ID is referenced by multiple repositories, you must delete all tags or force removal with -f.
3) Prune unused images
Use docker image prune to clean up dangling layers and free space.
# docker image prune -f
Total reclaimed space: 1.6 GB6. Export and Import Images
1) Export (save) an image
Export syntax:
# docker save -o /data/ubuntu:18.04.tar ubuntu:18.04
# ls /data
ubuntu:18.04.tarThe -o flag specifies the output file.
2) Import (load) an image
Use docker load to import a tar archive back into the local registry.
Import syntax:
# docker load -i ubuntu:18.04.tarAll image history and metadata are preserved.
7. Push Images to a Registry
Use docker push to upload an image to Docker Hub (login required).
Example:
# docker tag ubuntu:18.04 qinlulu/myubuntu:v1
# docker login
# docker push qinlulu/myubuntu:v1Verify the image on https://hub.docker.com.
Command Summary
1. Search images
docker search mysql2. Pull image
docker pull ubuntu:18.043. List local images
docker images4. Inspect image
docker inspect ubuntu:18.045. View image history
docker history ubuntu:18.046. Tag image
docker tag ubuntu:latest myubuntu:v17. Delete image
docker rmi myubuntu:v18. Prune temporary images
docker image prune -f9. Export image
docker save -o ubuntu.tar ubuntu:18.0410. Import image
docker load -i ubuntu.tar11. Push image
docker push qinlulu/myubuntu:v1Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
