Search code examples
dockertektontekton-pipelines

How do I use a custom container image in a Tekton step?


I'm new to Tekton and Tekton Pipelines. The examples I found use standard container images in the Tekton task steps. For example, the following step uses a standard ubuntu container to run a shell script:

  steps:
    - name: test-step
      image: ubuntu
      script: |
        #!/bin/sh
        echo "testing"
       

I would like to use my own custom container with custom applications in a Tekton step:

  steps:
    - name: custom-step
      image: custom-container
      script: |
        #!/bin/sh
        customCommand arg1 arg2

How do I do this? I found Tekton Tasks and Pipelines Container Contract, which describes the "contract" that a custom container must follow. However, I still don't understand how to define and use a custom container. Specifically,

  • How is the custom container image actually defined? An example Dockerfile would be helpful.
  • How do I tell Tekton where my custom container image is located? Do I need save my custom container image in a Docker image repository?

Is there an example showing how to create and use a custom container image that I can refer to? Thanks.


Solution

  • How is the custom container image actually defined? An example Dockerfile would be helpful.

    You can use any docker container. You can first test that it works on your local machine using docker run <container>. You need to carefully think about the exit code of your main process in the container, 0 means success and any other number means that it failed, Tekton use this signal to signal if the Task is successfully run or failed.

    How do I tell Tekton where my custom container image is located? Do I need save my custom container image in a Docker image repository?

    The containers for Tekton are run in Kubernetes. You need to make your container available on a container registry that your Kubernetes cluster can pull them from. This is the same process to how you make the container images available for Kubernetes for your applications in the cluster. E.g. docker push <container-registry-and-image-name>