skip to content
Alvin Lucillo

Connecting to MongoDB docker from Minikube

/ 1 min read

💻 Tech

Let’s say you have set up your k8s resources in Minikube and you want to connect one of of your pods to a MongoDB hosted in a Docker container outside the Minikube cluster? This is provided that Minikube and the Docker container share the same Docker daemon. For more details, let’s be specific. You have an Ubuntu WSL instance with Docker installed. You’ve set up you Minikube with deployed k8s resources. Now, you’ve spun a MongoDB container using docker run. You cannot use localhost as your DB hostname because in the perspective of the pod, this pertains to itself. The solution is to use the Docker’s IP as the DB hostname.