Build docker image, tag with built image id, push the image

10/26/2018

Background: Running Kubernetes on Google Cloud.

Because Kubernetes won't tolerate :latest tag for Rolling Updates, I'd find something like this useful.

docker build . -t gcr.io/project/nginx:{built_image_id} && docker push gcr.io/project/nginx:{built_image_id}

I saw a blog post about using git commit hash as a tag. Any other alternatives to skip the "copy git hash step"?

Thanks

-- Kaspar Püüding
docker
google-kubernetes-engine
kubernetes

2 Answers

10/27/2018

From Denis's answer. I got this, which should do the job.

docker build . -t gcr.io/project/nginx:$(git rev-parse --short HEAD) && docker push gcr.io/project/nginx:$(git rev-parse --short HEAD)

-- Kaspar Püüding
Source: StackOverflow

10/27/2018

According to Kubernetes documentations:

“ Doing a rolling update from image:latest to a new image:latest will fail, even if the image at that tag has changed. Moreover, the use of :latest is not recommended,”

They provided some best practices for configuration to help, that you can check in the following link and use as a guide.

-- Taame Amine
Source: StackOverflow