A tag like nginx:alpine points to a different image every few weeks. Before a risky upgrade I want a record of exactly which images ran, and Compose can write that record for you.
docker compose config --lock-image-digests -o compose.digests.yaml
The result is a small override file with one line per service, such as image: docker.io/library/nginx:alpine@sha256:.... Start the project with it and Compose uses those exact images, whatever the tags point to today:
docker compose -f compose.yaml -f compose.digests.yaml up -d
That makes a handy rollback point. Keep the file next to your backup, upgrade with the normal file, and if the new version misbehaves, start again with the digests file. Put it in git too and you can see later which image ran in which week.
The digests are looked up in the registry, so the command needs network access and only works for images that live in one. Locally built images without a registry copy cannot be pinned this way. A pinned digest only helps while the registry still has that image; some publishers clean up old ones, so for a true safety net also keep the image itself with docker save.
Further reading: docker compose config