Sofia Gonzalez
Sofia Gonzalez

Reputation: 11

Run Docker Image from Tekton Task

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

Upvotes: 1

Views: 2080

Answers (2)

Abdennour TOUMI
Abdennour TOUMI

Reputation: 93481

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.

Upvotes: 0

jsk
jsk

Reputation: 31

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.

Upvotes: 1

Related Questions