Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent docker images on docker hub from being overwritten?

Is there any way to prevent images being uploaded to docker hub with the same tags as existing images? Our use case is as follows.

We deploy to production with a docker-compose file with the tags of images as version numbers. In order to support roll-back to previous environments and idempotent deployment it is necessary that a certain tagged docker image always refer to the same image.

However, docker hub allows images to be uploaded with the same tags as existing images (they override the old image). This completely breaks the idea of versioning your images.

We currently have work-arounds which involve our build scripts pulling all versions of an image and looking through the tags to check that an overwrite will not happen etc. but it feels like there has to be a better way.

If docker hub does not support this, is there a way to do docker deployment without docker hub?

like image 664
Russell Avatar asked Jul 24 '15 08:07

Russell


People also ask

Is it safe to use images from Docker Hub?

These are high-quality Docker images, but they are not security vetted. So, although they are considered safe in general, you should still watch out for vulnerabilities. Public: Anyone can publish images on Docker Hub. You should never trust an unverified public image, and you need to be extra careful.

Does docker load overwrite?

As shown in docker load page, it "restores both images and tags." So an image from the same name doesn't get overwritten.

Do docker images expire?

After 30 days, the expectation is they would be required to pull again or at least log into the registry. Any time we remove someone's registry access, the container will be invalid at a max of 30 days later.

How do I trust a docker image?

Content trust is disabled by default in the Docker Client. To enable it, set the DOCKER_CONTENT_TRUST environment variable to 1 . This prevents users from working with tagged images unless they contain a signature.


2 Answers

The tag system has no way of preventing images been overwritten; you have to come up with your own processes to handle this (and h3nrik's answer is an example of this).

However, you could use the digest instead. In the new v2 of the registry, all images are given a checksum, known as a digest. If an image or any of its base layers change, the digest will change. So if you pull by digest, you can be absolutely certain that the contents of that image haven't changed over time and that the image hasn't been tampered with.

Pulling by digest looks like:

docker pull debian@sha256:f43366bc755696485050ce14e1429c481b6f0ca04505c4a3093dfdb4fafb899e

You should get the digest when you do a docker push.

Now, I agree that pulling by digest is a bit unwieldy, so you may want to set up a system that simply tracks digest and tag and can verify that the image hasn't changed.

In the future, this situation is likely to improve, with tools like Notary for signing images. Also, you may want to look at using labels to store metadata such as git hash or build number.

like image 54
Adrian Mouat Avatar answered Sep 28 '22 07:09

Adrian Mouat


Assuming you have a local build system to build your Docker images: you could include the build number from your local build job in your tag. With that you assure your requirement:

... it is necessary that a certain tagged docker image always refer to the same image.

When your local build automatically pushes to docker hub it is assured that each push pushes an image with a unique tag.

like image 40
Henrik Sachse Avatar answered Sep 28 '22 08:09

Henrik Sachse