How can I run a docker image in a kubernetes pod?
A teammate of mine has defined a new docker image and pushed it to my team's private registry. I own some code running in our kubernetes cluster and we need to get my code to effectively docker run gcr.io/our-project/teammates-image:latest
.
I've been looking at enabling docker-in-docker on our kubernetes pods but I'm having little luck. I'm currently experimenting with minikube
and whenever I try to docker run
I get: docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
.
I've added
securityContext:
privileged: true
To my container spec. I suspect I need more configuration but haven't figured out what.
I'm also trying to evaluate whether I can kubectl run --image=gcr.io/our-project/teammates-image:lastest
from within the kubernetes pod.
Is there a "correct" way to run docker images from within a kubernetes pod? How can I run image with docker-in-docker?
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 subprocess subprocess.run(["kubectl", "run", "teammates-image", "--image", "gcr.io/our-project/teammates-image:lastest", "--attach", "--restart", "Never", "--rm"])
This should:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With