If I build an image from Dockerfile or docker-compose.yml which target something like “nginx:latest” or “node:latest” for tests, I can’t rebuild the image and be sure it work again, because the nginx or node version can have changed.
And if I run the “docker build --from-lock .” command, it will rerun the Dockerfile (or docker-compose.yml) but don’t search images by current versions on the hub, just get hub image by lock version.
If any locked image was deleted or unreachable, the system can make a warning and ask for default image.
If I just run docker build, it will build normally the image and update the Dockerfile-lock.
I have made cli-plugin, docker-lock, that manages image digests for docker and docker-compose in a separate lockfile.
Here is an excerpt from the README:
docker-lock is a cli-plugin that uses Lockfiles (think package-lock.json or Pipfile.lock) to manage image digests. With docker-lock, you can refer to images in Dockerfiles or docker-compose files by mutable tags (as in python:3.6) yet receive the same benefits as if you had specified immutable digests (as in python:3.6@sha256:25a189a536ae4d7c77dd5d0929da73057b85555d6b6f8a66bfbcc1a7a7de094b).
docker-lock ships with 3 commands that take you from development to production:
docker lock generate finds base images in your docker and docker-compose files and generates a lockfile containing digests that correspond to their tags.
docker lock verify lets you know if there are more recent digests than those last recorded in the lockfile.
docker lock rewrite rewrites Dockerfiles and docker-compose files to include digests.