An image is a packaged, executable artifact containing the application code, libraries, environment variables, and configuration files needed to run a container.
Searching for Images
The docker search command queries Docker Hub for available images.
docker search [OPTIONS] TERM
Useful options:
-f, --filterapply a filter condition--formatcustomize output using Go templates--limitset the maximum number of results (default 25)--no-truncdisable output truncation
Example: search for images contianing "centos" and restrict results to official ones.
docker search -f is-official=true centos
Pulling Images
Download images from a registry with docker pull.
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
-a, --all-tagsdownloads every tag of the given image.
# latest Ubuntu image
docker pull ubuntu
# specific version
docker pull ubuntu:16.04
Listing Local Images
Display locally stored images using docker images.
docker images
# filter by name
docker images ubuntu
# wildcard matching
docker images cent*
# specify tag with a pattern
docker images ubun*:16.04
Removing Images
Delete one or more images from the local store.
docker rmi [OPTIONS] IMAGE [IMAGE...]
# or
docker image rm [OPTIONS] IMAGE [IMAGE...]
-f, --forceforce removal when image is referenced.
Delete by repository name:
docker rmi ubuntu
Delete by ID (a unique prefix is sufficient):
docker rmi 9f3
Exporting and Importing Images
Backing Up with docker save
Save images into a tar archive.
docker save [OPTIONS] IMAGE [IMAGE...]
-o, --outputspecify the output file (default stdout).
docker save ubuntu:16.04 94e814 -o linux.tar
Loading an Archive with docker load
Import images from a tar file created by save.
docker load [OPTIONS]
-i, --inputread from a file instead of stdin-q, --quietsuppress progress information
docker load -i linux.tar
When saving by ID without tags, the loaded image may appear with <none> for name and tag. Prefer saving by repository:tag.
Renaming Images
Create a new repository reference (and tag) to an existing image.
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
docker tag 94e ubuntu:18.04
Inspectinng Image Details
View low-level metadata with docker image inspect (or docker inspect).
docker image inspect [OPTIONS] IMAGE [IMAGE...]
-f, --formatoutput a specific field using Go templates.
# full JSON details
docker image inspect ubuntu:18.04
# extract the image ID
docker image inspect -f "{{ .Id }}" ubuntu:18.04
# storage driver data
docker image inspect -f "{{ .GraphDriver.Data }}" ubuntu:18.04
Viewing the Layer History
Show the layers and their creation commands with docker history.
docker history [OPTIONS] IMAGE
-H, --humanprint sizes and dates in human-readable form (default true)-q, --quietdisplay only IDs--no-truncshow full output without truncation
docker history ubuntu:18.04