Browse topics

Pulling images and pinning digests

Version
29
Review
Draft

Summary#

docker pull downloads an image from a registry. A tag can later point to different content, while a repository@sha256:... digest reference keeps naming the same content.

Syntax#

sh
docker pull REPOSITORY:TAG
docker pull REPOSITORY@sha256:DIGEST
docker pull --platform linux/amd64 REPOSITORY:TAG
docker image ls REPOSITORY
docker image rm REPOSITORY:TAG

Example#

Run this example on a disposable Docker daemon with no local busybox images. A pull can move an existing tag.

sh
(
  set -eu
  image="busybox:1-musl"
  if [ -n "$(docker image ls --quiet busybox)" ]; then
    echo "Use a daemon without local busybox images." >&2
    exit 1
  fi
  digest=
  trap 'docker image rm "$image" ${digest:+"$digest"} >/dev/null 2>&1 || true' EXIT

  docker pull --quiet "$image"
  digest=$(docker image inspect --format '{{index .RepoDigests 0}}' "$image")
  case $digest in
    busybox@sha256:*) echo "repository digest recorded" ;;
  esac

  docker pull --quiet "$digest" >/dev/null
  by_tag=$(docker image inspect --format '{{.Id}}' "$image")
  by_digest=$(docker image inspect --format '{{.Id}}' "$digest")
  [ "$by_tag" = "$by_digest" ] && echo "tag and digest name the same image"
  docker image ls --format '{{.Repository}}:{{.Tag}}' "$image"
)

Expected output#

Text
docker.io/library/busybox:1-musl
repository digest recorded
tag and digest name the same image
busybox:1-musl

Common mistakes#

A local tag is not refreshed just because the registry moved it. docker run uses the cached image by default, so pull again or use --pull always. A digest pin also stops security updates until you change the digest. Remove by tag to drop a specific name. Forcing removal by image ID can remove every tag that points to that image.

Version applicability#

Checked with Docker Engine 29. Omitting the tag means latest, which is an ordinary tag with no promise that it is the newest release.

Sources#

Attribution
DevLookup contributors
License
CC-BY-4.0