How to run docker image in Kubernetes pod? How to run docker image in Kubernetes pod? kubernetes kubernetes

How to run docker image in Kubernetes pod?


Here's the solution I ended up using for anyone who may stumble upon this in the future.

Install kubectl in the main docker image which needs to run the other docker image. I did this by following these docs. Once you have kubectl installed, it should automatically be able to interact with the cluster it's running in and doesn't need extra authentication.

Next, to run the teammtes-image:latest docker image you can do something like the following in python:

import subprocesssubprocess.run(["kubectl", "run", "teammates-image", "--image", "gcr.io/our-project/teammates-image:lastest", "--attach", "--restart", "Never", "--rm"])

This should:

  1. create a pod
  2. run the image
  3. return the return code of the container
  4. delete the pod after completion