Kaniko - Adding Extra Tags to Container Image

Cloud TunedCloud Tuned
1 min read

Problem Statement

I recently needed to add some extra tags to container images already published to the container image registry. I use Kaniko to build my images. Kaniko cannot directly add extra tags to a container image that has already been pushed to a container image registry without rebuilding or re-pushing. Kaniko's primary function is to build container images from a Dockerfile and push them to a registry.

Alternative Approach 1

However, when you build an image with Kaniko, you can specify multiple tags for that image during the initial push. This is achieved by using the --destination flag multiple times in your Kaniko executor command. Each --destination flag specifies a different tag for the same image, and Kaniko will push the image with all of these specified tags simultaneously.

Example:

/kaniko/executor \
  --context /path/to/your/context \
  --dockerfile /path/to/your/Dockerfile \
  --destination your-registry/your-image:latest \
  --destination your-registry/your-image:v1.0.0 \
  --destination your-registry/your-image:commit-sha

In this example, Kaniko would build the image and push it to your-registry/your-image with three different tags: latest, v1.0.0, and commit-sha.

Alternative Approach 2

If an image has already been pushed to a registry and you need to add a new tag, you would typically use a tool designed for image management, such as Docker CLI or crane, to pull the image, add the new tag, and then push it back to the registry. Kaniko itself is not designed for this "retagging" operation on already existing images.

0
Subscribe to my newsletter

Read articles from Cloud Tuned directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Cloud Tuned
Cloud Tuned