1

Question: Given a tag of an image on dockerhub such as ubuntu:22.04 what cli command determines the SHA-256 that can be used instead of the tag in a FROM instruction in a Dockerfile?

I have tried docker images ubuntu:22.04 --format "{{.ID}}" --no-trunc but that does not produce an ID that works, more context on what I am trying todo below.

I have docker file that looks like this

FROM ubuntu:22.04
RUN apt-get update -y \ 
&& apt-get install -y jq git curl

I would like to resolve the id of the tag 22.04 tag using a command line so I can write a docker file that looks something like

ARG ID
FROM ubuntu@$ID
RUN apt-get update -y \ 
&& apt-get install -y jq git curl

with the goal of being able to set the id arg from the CLI with the command

docker build . \
  --tag shell \
  --build-arg ID=$(docker images ubuntu:22.04 --format "{{.ID}}" --no-trunc)

the above command errors out with output below

[+] Building 0.1s (3/3) FINISHED                                                                                                                                                                                                                   
 => [internal] load build definition from Dockerfile                                                                                                                                                                                          0.0s
 => => transferring dockerfile: 36B                                                                                                                                                                                                           0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                             0.0s
 => => transferring context: 2B                                                                                                                                                                                                               0.0s
 => ERROR [internal] load metadata for docker.io/library/ubuntu@sha256:df5de72bdb3b711aba4eca685b1f42c722cc8a1837ed3fbd548a9282af2d836d                                                                                                       0.0s
------
 > [internal] load metadata for docker.io/library/ubuntu@sha256:df5de72bdb3b711aba4eca685b1f42c722cc8a1837ed3fbd548a9282af2d836d:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: encountered unknown type ; children may not be fetched

when I run docker images ubuntu:22.04 --format "{{.ID}}" --no-trunc I get sha256:df5de72bdb3b711aba4eca685b1f42c722cc8a1837ed3fbd548a9282af2d836d as the output

Question: Given a tag of a container on dockerhub what cli command determines the SHA-256 that can be used instead of the tag in a FROM instruction in a Dockerfile?

ams
  • 60,316
  • 68
  • 200
  • 288

1 Answers1

1

It seems that the container ID is not the right value to use. Instead a manifest SHA-256 is required.

docker manifest inspect ubuntu:22.04 returns JSON object that includes cpu architecture specific manifests SHA256s. With jq magic the following command works

docker build . \
  --tag shell \
  --build-arg ID=$(docker manifest inspect ubuntu:22.04 | jq -r '.manifests | .[] | select(.platform.architecture == "amd64") | .digest')

A friend pointed me at some open bugs related to this https://github.com/docker/hub-feedback/issues/1925 and https://github.com/docker/hub-feedback/issues/2043

ams
  • 60,316
  • 68
  • 200
  • 288