We are using automated Docker hub builds to create our application images automatically whenever new commit is pushed to github.
That works well when we manually change the tag on docker hub. Now what we want is to create the image tag automatically as git commit sha so that we can pull that image in our kubernetes deployment for rolling updates
we want some thing like this,
when commit foo is pushed in our application repository,
docker hub will build the image automatically and we will have new image on dockerhub as
myimage:foo
I did not find the documentation to achieve this on docker hub. How can one achieve this ?
Thanks.
To push an image to Docker Hub, you must first name your local image using your Docker Hub username and the repository name that you created through Docker Hub on the web. You can add multiple images to a repository by adding a specific :<tag> to them (for example docs/base:testing ).
A Docker image's ID is a digest, which contains an SHA256 hash of the image's JSON configuration object. Docker creates intermediate images during a local image build, for the purposes of maintaining a build cache. An image manifest is created and pushed to a Docker registry when an image is pushed.
Make a new executable file in hooks/
called post_push
with these contents to push another image with the latest git short hash as its tag:
#!/bin/bash
SHORTHASH="$(git rev-parse --short HEAD)"
docker tag $IMAGE_NAME $DOCKER_REPO:$SHORTHASH
docker push $DOCKER_REPO:$SHORTHASH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With