How to use local Docker images with Minikube?

Harold Finch
2 min readMay 23, 2024

--

How to use local docker images with Minikube?

Using local Docker images with Minikube involves a few straightforward steps. Minikube can be configured to use the Docker daemon from the host system, allowing it to access locally built images directly. Here’s how to do it.

Step-by-Step Guide

  1. Start Minikube with Docker Driver

Ensure Minikube is started with the Docker driver, which allows it to share the Docker daemon with your local machine.

minikube start --driver=docker

2. Point Docker CLI to Minikube’s Docker Daemon

Set the Docker environment to use Minikube’s Docker daemon. This allows you to build and manage Docker images directly in Minikube’s context.

eval $(minikube docker-env)

3. Build Your Docker Image

Build your Docker image as you normally would. Since the Docker environment is now set to Minikube’s Docker daemon, the image will be available directly within Minikube.

docker build -t my-local-image:latest .

4. Verify the Image is Available in Minikube

List the Docker images to ensure your image is available in Minikube’s Docker daemon.

docker images

You should see my-local-image:latest listed.

5. Deploy to Minikube

Create a Kubernetes deployment using the local image. Since the image is already in Minikube’s Docker daemon, Kubernetes can pull it directly without needing a registry.

apiVersion: apps/v1
kind: Deployment
metadata:
name: my-local-deployment
spec:
replicas: 1
selector:
matchLabels:
app: my-local-app
template:
metadata:
labels:
app: my-local-app
spec:
containers:
- name: my-local-container
image: my-local-image:latest
ports:
- containerPort: 8080

Apply the deployment

kubectl apply -f deployment.yaml

6. Check the Deployment

Verify that the pod is running correctly using the image you built.

kubectl get pods

You should see your pod running.

Switching Back to Default Docker Daemon

Once you have built and deployed your image, you can switch your Docker CLI back to the default Docker daemon on your host machine if needed.

eval $(minikube docker-env --unset)

Additional Tips

  • Minikube Cache: Alternatively, you can use Minikube’s caching feature to add local images to the Minikube environment:
minikube cache add my-local-image:latest
  • Rebuilding Images: If you rebuild the Docker image, ensure you restart the pods in Minikube to pick up the latest image changes:
kubectl rollout restart deployment/my-local-deployment

By following these steps, you can effectively use local Docker images with Minikube, streamlining your development and testing workflows without the need to push images to a remote registry.

We are VaST ITES INC, a DevOps consulting services company based in the Canada. We help businesses of all sizes adopt and implement DevOps practices to improve their software development and delivery processes.

Contact us for a free Consultation

Reach out to us now: 🤝
🌐 https://vastites.ca/contact-us/
☎️ +1 3127249560
📩 info@vastites.ca

--

--