docker / docker/cli

Suggestion: a "docker pull --dry-run" option

Open
#6,059 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

kind/feature status/0-triage
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

Description

It would be useful in some automation environment to detect if there are new images available without pulling them right away. In my case, the launcher script detects if there is an update, and offers it to the user.

In an ideal world, I would launch docker pull --dry-run and either parse the output or check the return code.

Migrated from this issue, as suggested in the thread to make a feature request in the Docker CLI :
https://github.com/distribution/distribution/issues/2412

Workaround:

It is possible to achieve this using image inspection. The following script works in my case but has major flaws : is is slow, will break if the manifest structure changes, and works only because the variant I use happens to be the first in the remote repo's manifest. I feel that there is nothing better that a docker pull to know what a docker pull should be doing, and any scripting attempt like this one is an approximation.

    images=$(docker compose config | grep 'image:' | awk '{print $2}')
    for image in $images; do
        # Get the local digest in the format sha256:<hash>
        localDigest=$(docker image inspect --format='{{index .Id}}' $image 2>/dev/null)
        if [[ $? -ne 0 ]]; then
            echo "At least one image not found locally: $image"
            updatesFound=true
            break
        fi
        echo $localDigest

        # Get the remote digest in format sha256:<hash>
        # This works ONLY if the desired config is from the first variant
        # Would have been cleaner with jq but it is not available in a git bash on Windows...
        remoteDigest=$(docker manifest inspect -v $image \
            | awk '/"config":/ {found=1} found&& /"digest"/ {print $2; exit}' \
            | tr -d '",')
        echo $remoteDigest

        # Perform comparison
        if [[ "$localDigest" == "$remoteDigest" ]]; then
            echo "Up to date: $image"
        else
            echo "At least one image outdated: $image"
            updatesFound=true
            break
        fi
    done

EDIT: Workaround does not work on a mac, as the content of docker image inspect differs.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no specific files or tests. Start by tracing the Docker CLI's docker pull command entry point and establish the expected dry-run behavior for image availability, return status, output, and multi-platform images. Done means the agreed behavior is implemented and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.