How can I revert my last push on hub.docker.com? - docker

I have damaged my working docker image by pushing and overwriting by a faulty docker image on hub.docker.com. How can I revert the last push?

There is no revert option that I'm aware of. If you have a good copy of your image somewhere, you can repush that to the registry. To avoid this issue in the future, follow one or more of these steps:
Avoid using the latest tag and give each build a unique tag.
Use a reproducible build process with a Dockerfile that is saved in version control which uses specific versions for all dependencies. This allows you to checkout a previous state of the Dockerfile to rerun a previous build.
Maintain a private registry of your own for your images and any dependencies you have on other images. Make sure to maintain those dependencies (updating periodically) and backup your registry.

You can use the Advanced Image Management page in docker hub to copy the digest of the good image, pull it to your system, overwrite the tag, then push back. Use these commands:
docker image pull myname/example#sha256:1234
docker tag myname/example#sha256:1234 myname/example:mytag
docker push myname/example:mytag
Assuming myname/example#sha256:1234 is your copied digest of the good image from docker hub, myname/example:mytag is what you want to tag the image as.

Related

Rebuild docker image by reusing the same tag?

I've gone thru multiple questions posted on the forum but didn't get a clarity regarding my requirement.
I'm building a docker image after every successful CI build, there will be hardly 1 to 2 lines of changes in Dockerfile for every successful build.
Docker Build Command:
$(docker_registry)/$(Build.Repository.Name):azul
Docker Push Command
$(docker_registry)/$(Build.Repository.Name):azul
I wanted to overwrite the current docker image with the latest one(from the latest CI build changes) but retain the same tag - azul. Does docker support this ?
Yes, docker supports it. Every line you execute results in a new layer in image, that contains the changes compared to the previous layer. After modifying the Dockerfile, new layers will be created and the same preceding layers will be reused.
If you want to clean build the whole image with no cached layers, you can use the —no-cache parameter.
Mechanically this works. The new image will replace the old one with that name. The old image will still be physically present on the build system but if you look at the docker images output it will say <none> for its name; commands like docker system prune can clean these up.
The problems with this approach are on the consumer end. If I docker run registry.example.com/image:azul, Docker will automatically pull the image only if it's not already present. This can result in you running an older version of the image that happens to be on a consumer's system. This is especially a problem in cluster environments like Kubernetes, where you need a change in the text of the image name in a Kubernetes deployment specification to trigger an update.
In a CI system especially, I'd recommend assigning some sort of unique tag to every build. This could be based on the source control commit ID, or the branch name and bind number, or the current date, or something else. You can create a fixed tag like this as a convenience to developers (an image is allowed to have multiple tags) but I'd plan to not use this for actual deployments.

Fork docker repository

I want to keep the images that I used in my docker hub account while maintaining reference to the pulled image. Something like when you fork a project in github.
Currently I have tried jwilder/nginx-proxy image. Now that I am satisfied with it, I committed the working container to username/nginx-proxy image and push it.
The problem with this approach is it is like a fresh image and it doesn't show the layer from jwilder/nginx-proxy. No documentation or even Dockerfile.
If you push the image, there is no reference to the original, that behavior is normal. You can put that reference or link using your "repo info".
The Dockerfile is only shown if you did an automated build linking your github or bitbucket account and the push is automatically done based on the Dockerfile of your project.

How do I make a Docker hub use the same image for "latest" and "vX.Y"?

Docker Hub builds a Syncthing image for me from this source repo.
I tagged the latest commit v0.13.5, but Docker built it twice: once for latest and once for v0.13.5.
Why? Shouldn't it be able to figure out the source is the same? Am I just doing something dumb in my Dockerfile, breaking caching? Is there some way I need to hint to Docker Hub that this should really be two images with the same checksum but different tags?
I'm thinking of the two Docker image tags latest and v0.13.5 like two git tags both pointing to the same commit. Shouldn't Docker Hub work that way too? If someone tries to pull latest they'd pull exactly the same image tagged v0.13.5? I know how to pull/re-tag/push, but again, seems like there just must be some way to get Docker Hub to do this automatically.
Build settings:
With a little magic, Docker Hub can do this! Pablo Chico de Guzmán helped me out.
Steps:
add a file called hooks/post_push
make hooks/post_push executable, commit and push
delete the "Branch" build, but leave the "Tag" build in place
Now, any tags I push (e.g. git push --tags) fire off an automated build, and the same image is also given the latest tag.
Here's the change I had to make so the most recent "vX.Y"-tagged meonkeys/syncthing image is also tagged latest.
Latest is just “the last build/tag that ran without a specific tag/version specified”.
If you push a tagged image it does not replace the current image tagged with latest. If you push tagged images only, latest tag is not added.
Automated Builds on Docker Hub is adding the latest tag automatically for the master branch.

How to install Dockerfile from GitLab to allow pull and commit

Is there a way to clone a Dockerfile from GitLab with the docker command?
I want to use the feature that allow pull and commit.
I am not sure if I have understand well but these pull and commit update the Dockerfile from the git repositories ? Or is it only locally in the next images ?
If not, is there a way to get all the change you made from the previous image made by the Dockerfile into another Dockerfile ?
I know you can clone with Git directly, but like for npm, you can also use Git url like git+https:// or git+ssh://
The pull/commit commands affect the related image and operate directly against your configured registry, which is the official Docker Hub Registry unless configured otherwise. Perhaps some confusion may arise from the registry's support for Automated Builds, where the registry is directly bound to a repository and rebuilds the image every time the targeted repository branch changes.
If you wish to reuse someone's Docker image, the best approach is to simply reference it via the FROM instruction in your Dockerfile and effectively fork the image. While it's certainly possible to clone the original source repository and continue editing the Dockerfile contained therein, you usually do not want to go down that path.
So if there exists such a foo/bar image you want to continue building upon, the best, most direct approach to do so is to create your own Dockerfile, inherit the image by setting it as a base for your succeeding instructions via FROM foo/bar and possibly pushing your baz/bar image back into the registry if you want it to be publicly available for others to re-base upon.

Images are being cached even if there are changes

I have on Docker an automatic build for an image based on ubuntu with some custom configurations to re-use then as base image on other specific Dockerfiles for particular projects. This works okay.
I made a change to it, committed to github which then started and did the automatic build on Docker.
From one of these other projects, I'm calling at the beginning of the Dockerfile FROM myuser/myimage but its not getting the last image with the changes, but rather it keeps caching the old one.
Shouldn't this be automatically?
You need to docker pull the latest version. Docker looks for the image from FROM locally. It doesn't notice if that tag has been updated in the registry where it came from. I have a script that runs docker pull before building images.

Resources