0

In a project with several references to certain Docker-images I want to provide a versionable (i.e git-trackable) way to use common names for Docker-images.

Currently at several places in an existing project some Bash/Python-scripts, Docker-files or Jenkins-files I'm referencing e.g. busybox:latest. Now I want to use readable names for unique images without redundancy instead.

As far as I understand I could use my own registry, provide a readable tag and just use the tag or the right repo-digest:

docker pull busybox:latest
docker tag busybox:latest my_registry/busybox:default
docker push my_registry/busybox:default

# use
docker pull busybox@sha256:dca712...86b  <- has to be maintained manually
# or
docker pull my_registry/busybox:default <- not updateable or not unique for given commit

But now I also want the distinct sha1s behind also be update-able and git-trackable (without having to redundantly write the sha everywhere). Maybe I'm not using the correct wording but what I need could be achieved by using a text-file containing some sort of "aliases", e.g.

docker_aliases.txt:

my_registry/busybox_default sha256:dafhs3ca712...3486b
my_registry/ubuntu-20.04 sha256:6a507907bd4e...a50

which could then somehow be used with all Docker-calls which involve pulling images and would allow me to

  • use my_registry/busybox_default as image specifier at all places
  • have one place to update those aliases
  • which could be tracked by git (very important)

It feels like everyone who's maintaining some larger CI should come across this problem. Is there a general solution for this?

3
  • 1
    How about a Dockerfile with just a FROM directive?
    – gronostaj
    Commented Jun 22, 2021 at 6:51
  • I wanted to write "did your read the question at all?", but then I understood, what you meant :) I'll give it a try but maybe you should turn your comment into an answer
    – frans
    Commented Jun 22, 2021 at 9:08
  • xkcd.com/530
    – frans
    Commented Jun 22, 2021 at 9:47

1 Answer 1

1

Create a Dockerfile with just a FROM directive pointing at the image you want to use. Track it with git. Always build it to the same tag. Use that tag everywhere.

  • You have the same image tag used everywhere
  • Updates are made in the Dockerfile
  • Changes are tracked by git

Alternatively, use a shell script that docker tags what's necessary. You can even trigger it from a git hook.

3
  • Unfortunately there is one more issue I didn't think about yet: if for some reason you need to work on different branches simultaneously (like on CIs), this approach does not work without a complicated locking-mechanism, since the meaning of e.g. busybox_default would be part of a Docker-wide state. Putting it inside a text file (which gets read every time you access busybox_default) still solves this problem. The best would be to have something like docker --image-aliases=aliases.txt build <IMG>
    – frans
    Commented Jun 22, 2021 at 13:59
  • @frans I don't think you can solve this with Docker by itself. Maybe with Docker-in-Docker, but I'm not sure.
    – gronostaj
    Commented Jun 22, 2021 at 14:18
  • Ok, I do it now like this: starting from the Dockerfile approach I don't just docker build and subsequently use this "alias image" using docker run, but instead I'm doing something like docker run $(docker build <dockerfile-dir> | grep "Successfully built" | awk '{print $3}') every time I need it. This way I don't introduce an extra file which is easier in most situations. Only Dockerfiles are a problem: here I have to inject the result of docker build .. using ARG and --build-args
    – frans
    Commented Jun 24, 2021 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .