Skip to main content

Kaniko container runtime error when pushing to a Docker registry

Conditions

  • Module: Harness CI
  • Environment:
    • Infrastructure: Kubernetes
    • OS: Linux

Problem

While building and pushing an image to a Docker registry, you get a kaniko container runtime error, such as:

1 info 01/11/2022 13:06:02 + /kaniko/executor --dockerfile=Dockerfile --context=dir://. --destination=**************/pythonsample:latest --snapshotMode=redo --digest-file=/kaniko/digest-file
2 info 01/11/2022 13:06:02 kaniko should only be run inside of a container, run with the --force flag if you are sure you want to continue
3 info 01/11/2022 13:06:02 exit status 1

Solution

This error can be resolved by adding a Docker container environment variable. To do this, add a stage variable named container with the value docker.

You can add stage variables in the Build stage settings, in the YAML editor, or in the pipeline's Variables list.

To add a variable to the pipeline's variables list:

  1. Select Variables on the right side of the Pipeline Studio.

  2. Locate the stage where you have the Build and Push an Image to Docker Registry step.

  3. Next to Stage Variables, select Add Variable, and configure the variable as follows:

    • Type: String
    • Name: container
    • Value: docker

  4. Select Save.

  5. Select Apply Changes.