skip to Main Content

Is it possible to run a docker image from a Tekton task? A majority of examples I have seen have to do with building and deploying Docker Images with Tekton, but nothing on how to run an already built image.

I am using a cron job to trigger a Tekton EventListener which then runs a Taskrun. I want the task to run a docker image hosted on a private docker repo. The Taskrun refers to this Task.

apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: update-ip
spec:
  steps:
    - name: update-ip
      image: [<private-docker-repo>]
      command: ["docker"]
      args: ["run", <private-docker-repo/path-to-image>]

Here is an example of common tutorials i see

https://developer.ibm.com/tutorials/build-and-deploy-a-docker-image-on-kubernetes-using-tekton-pipelines/

any help would be appreciated

2

Answers


  1. Your are looking for DinD ( Docker In Docker) feature with tekton:

    This is a complete example, and it should answer your need:

    focus on the sidecar section (L42 -> L66) where the dind container is added.

    Login or Signup to reply.
  2. The "task" of each Tekton task is to run a container (image). So, it will be sufficient to state your container image, and that’s it.

    Your example should look like

    apiVersion: tekton.dev/v1alpha1
    kind: Task
    metadata:
      name: update-ip
    spec:
      steps:
        - name: update-ip
          image: <private-docker-repo/path-to-image/image-name:image-tag>
    

    command and args are optional, if you want to execute something else than the ENTRYPOINT and/or CMD, that is defined by your container image.
    For even more flexibility, you can alternatively state a script, which allows to execute several commands within your container, like a shell script.

    Hints:

    • For your private registry, remember to add a pull secret to the service account (if your repo has restricted access).
    • In newer versions of Tekton, the apiVersion changed to tekton.dev/v1beta1.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search