Skip to content

Docker image management

Docker image management encompasses the lifecycle operations for container images, including searching, pulling, tagging, pushing, and deleting images within a local or registry environment^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].

Core Concepts

Image Naming Convention

Docker images adhere to a specific naming structure to ensure unique identification across registries^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].

The general syntax is: ${registry_name}/${repository_name}/${image_name}:${tag_name}

For example: docker.io/library/alpine:3.10.1^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].

Image Storage and Transfers

Docker images are composed of layers. When transferring images (e.g., during a push or pull), only the changed layers are transferred, not the entire image^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md]. This layering optimizes storage and network bandwidth, meaning updates are typically fast after the initial transfer^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].

Management Commands

Searching and Pulling

To find images, use the search command to query a registry^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md]. * docker search <keyword>: Searches for images on Docker Hub (or the configured registry). * docker pull <image_name>: Downloads an image to the local host^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].

You may pull specific versions by appending the tag (e.g., alpine:3.10.3); omitting the tag usually defaults to the latest version^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].

Listing Images

To view images stored locally, use the following commands^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md]: * docker images * docker image ls

Tagging

The docker tag command creates a reference (an alias) to a source image, effectively assigning it to a specific repository or version^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].

  • Syntax: docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
  • Example: docker tag 965ea09ff2eb docker.io/909336740/alpine:v3.10.3^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md]

This prepares the image for pushing to a specific registry path.

Pushing Images

To upload a local image to a remote registry (like Docker Hub), you must be logged into the registry^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].

  • Syntax: docker push [OPTIONS] NAME[:TAG]
  • Prerequisite: docker login <registry_url>^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md]

Once authenticated, the push command uploads the image layers to the specified repository^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].

Removing Images

To delete an image from the local filesystem, use the remove image command^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].

  • Syntax: docker rmi [OPTIONS] IMAGE [IMAGE...]
  • Force Delete: Use the -f flag to force deletion, typically used if an image is currently in use by a stopped container^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].

Authentication

Login credentials are typically stored in a configuration file after authentication^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md]. * Command: docker login docker.io * Config Location: ~/.docker/config.json^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md]

Sources

  • 400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md