DEV Community

Alessio
Alessio

Posted on

Which of my Docker containers are behind? A read-only check that fits in cron

Pulling and restarting is easy to automate. Knowing what would change before you do it is the part I kept skipping.

On a single Docker host the question is simple: which of my running containers are on an image that is no longer the newest one? docker ps won't tell you. A floating tag like :latest or :7.2-alpine can be rebuilt upstream while your container keeps running the old digest, and a pinned tag like 1.21.0 never tells you that 1.21.3 exists.

So I built a small tool for that one question. Full disclosure: I wrote it. It's called imagenudge-lite: one Python file, standard library only (3.9+), MIT.

What it does

  • Lists running containers through the local Docker socket, using only GET requests.
  • Asks the registry whether the tag each container runs now points to a different digest (HEAD on the manifest, no layers downloaded).
  • Looks for a newer version tag in the same style and suffix: 1.25.1 is compared with X.Y.Z, 16-alpine with N-alpine, v2.10.4 with vX.Y.Z. Tags like latest or stable only get the digest check.
  • Prints a plain-text list. It never pulls, restarts or edits anything.

What the output looks like

This is the built-in --demo (sample data, no Docker, no network):

  UPDATE  gitea        gitea/gitea:1.21.0  newer tag 1.21.3
  UPDATE  redis-cache  redis:7.2-alpine    new digest for :7.2-alpine (b2b2b2b2b2b2 -> d4d4d4d4d4d4); newer tag 7.4-alpine
  OK      traefik      traefik:v2.10.4     digest matches :v2.10.4
  SKIP    my-app       my-app:dev          no registry digest locally (built or loaded locally?)

4 container(s): 2 update(s) available, 1 up to date, 1 skipped, 0 could not be checked.
Nothing was pulled or restarted. Review the changelog, then update when you choose.
Enter fullscreen mode Exit fullscreen mode

SKIP covers containers with nothing to compare (started from an image ID, pinned by digest only, or built locally). ERROR means the registry couldn't be checked (private image, rate limit, no network) and shows the reason.

Exit codes, so cron can use it

Exit code Meaning
0 Everything that could be checked is up to date (or nothing is running)
1 At least one container has an update available
2 Docker socket not reachable, bad arguments, or nothing could be checked
# check every morning at 07:00, keep the last report
0 7 * * * python3 /opt/imagenudge_lite.py > /var/log/imagenudge-lite.txt 2>&1
Enter fullscreen mode Exit fullscreen mode

It doesn't send alerts itself; scheduling and what you do with exit code 1 are up to you.

Limits, honestly

  • One local Docker socket (--socket for rootless, DOCKER_HOST if it's a unix:// path). No TCP/SSH hosts.
  • Public images only, anonymous access: Docker Hub, and registries that hand out anonymous pull tokens (public ghcr.io, quay.io). No credentials are read or sent.
  • It reads up to 3 pages (3,000 tags) of a tag list, so on huge repositories the "newer tag" hint can be lower than the real newest one.
  • Multi-arch images are compared by their index digest, which is what docker pull by tag records locally.

Question for you

How do you find out a container is behind today? Watchtower in monitor-only mode, Renovate on compose files, a calendar reminder, or "when something breaks"? And do you pin exact versions or ride floating tags?


pip install imagenudge-lite ยท https://github.com/alessio1999xx-debug/imagenudge-lite

Top comments (2)

Collapse
 
userxnom profile image
Abdullah Naseer •

The distinction you draw at the top is the whole post for me: pulling and restarting is easy to automate, knowing what would change before you do it is the part everyone skips. I like that imagenudge-lite answers only that one question, read-only, with a HEAD on the manifest and no layers downloaded โ€” that is exactly the check I would trust in cron, because a tool that can only report cannot accidentally restart the wrong thing at 7 a.m. The exit codes are the detail that sells it: 0, 1 and 2 turn a morning report into something cron can actually act on, instead of a log line I have to remember to read. My honest answer to your question is that I do not have a good system yet โ€” I notice drift when something breaks or when I rebuild by hand, which is the worst version of your check. What do you do about the 3,000-tag limit on a huge repository: does the newer-tag hint just go quiet, or does it warn you that it stopped looking?

Collapse
 
alessio99xx profile image
Alessio •

Thanks, and honestly "I notice drift when something breaks" is how most of us find out.

On the 3,000-tag limit: it goes quiet. The lite version reads up to 3 pages of the tag list, so on a huge repository the "newer tag" hint can point lower than the real newest tag, and it doesn't warn you that it stopped looking. The README says so, but the report itself doesn't. The digest check isn't affected, so "your tag was rebuilt upstream" is still reliable.

You're right that a silent cap is the worst kind for a cron tool. A one-line "tag list truncated, newer-tag hint may be incomplete" in the report is a cheap fix, so I'll add it.