A tag like latest can point at something new tomorrow. A digest cannot. I like crane, a small tool from the go-containerregistry project, for getting that digest without pulling the image.
crane digest nginx:latest
It asks the registry and prints the digest of the image, a sha256: string. With --full-ref it prints the whole reference with the digest in it, ready to paste:
crane digest --full-ref nginx:latest
That output is what you put in a Compose file or a Kubernetes manifest after the image name, written as image: name@sha256:.... The image then stays exactly the one you looked at, even if the tag moves.
There is also a --platform flag in the form os/arch, such as linux/amd64. The docs say it defaults to all platforms. For a multi-arch image I’d run the command both ways and compare, so I know whether I am pinning the whole multi-arch image or one architecture.
The caveat is the pin itself. A pinned digest never updates, so a security fix in the base image will not reach you until you look up the new digest on purpose.
Further reading: crane digest