How can I use local Docker images with Minikube?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
When working with a local development environment using Docker and Kubernetes, a common setup involves using Minikube as a local Kubernetes cluster. Minikube supports a variety of container runtimes, including Docker, which enables you to build and test your applications using local Docker images. This article walks you through the steps to effectively utilize local Docker images with Minikube, making the process more streamlined and efficient.
Prerequisites
Before we begin, ensure you have the following installed on your system:
- Minikube: The easiest way to set up a local Kubernetes cluster.
- Docker: The platform for building, running, and managing container applications.
- Kubectl: The Kubernetes command-line tool for managing clusters.
Docker Environment on Minikube
Minikube uses its own Docker daemon. If you build images on your local machine's Docker daemon, they are not directly accessible to Minikube unless explicitly pushed to a container registry. However, a more efficient way is to instruct your terminal session to use Minikube's Docker daemon.
Switching to Minikube's Docker Daemon
To configure your command line to use Minikube's Docker daemon, use the following command:
This command sets up environment variables such that any subsequent Docker commands run against the Docker daemon inside Minikube. You can build Docker images as you normally would, and they will be directly available to your Minikube cluster.
Building an Image with Minikube's Docker Daemon
Here's a sample Dockerfile for a simple Node.js application:
To build an image using Minikube's Docker daemon:
Deploying the Image on Minikube
Once the image is built, you can deploy it on Minikube like any other image:
Apply the deployment to Minikube:
Checking Your Deployment
After deployment, ensure everything is running correctly using:
Summary Table
| Step | Description |
| Switch Docker Daemon | Use eval $(minikube docker-env) to switch to Minikube's Docker. |
| Build Image | Use docker build as you would normally to build the Docker image. |
| Deploy on Minikube | Create a Kubernetes manifest and use kubectl apply to deploy. |
| Verify Deployment | Use kubectl get pods and kubectl logs to ensure it's running. |
Additional Considerations
- Resetting Docker Env: Once done with Minikube, reset your Docker environment by executing
eval $(minikube docker-env -u). - Leveraging Local Registry: For a more evolved setup, consider configuring a local Docker registry which Minikube can access, or use alternative container runtimes supported by Minikube like Podman.
- Persistence: Note that Minikube's Docker environment is ephemeral per VM session, hence built images may not persist across Minikube restarts.
By following the described steps, you can seamlessly integrate local Docker development with a Minikube cluster, promoting a smoother development workflow without unnecessary image pushes to a remote registry. This setup is ideal for local testing and development, expediting the build-test loop owing to its localized nature.
Related reading
- How can I use local Docker images with Minikube?
- How can kubernetes pods discover each other?
- How can one pipe stdin into a container in a pod in Kuberentes?
- How can the OR selector be used with labels in Kubernetes?
- How can systemd and systemctl be enabled and used in Ubuntu Docker containers?
- How can we add capabilities to a running docker container?
- How can we create service dependencies using kubernetes
- How can we delete existing role in kubernetes?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.