Learn how to leverage your locally built Docker images for development and testing within a Minikube environment.
This document provides a step-by-step guide on how to deploy a local Docker image to Minikube.
Build your Docker image locally. Make sure to tag it appropriately:
docker build -t my-image:latest .Start Minikube and configure your shell to use its Docker daemon:
minikube start
eval $(minikube docker-env)Now you can use the my-image:latest image in your Kubernetes deployments just like any other image. Kubernetes will pull it from your local Docker daemon, which is now managed by Minikube.
apiVersion: apps/v1
kind: Deployment
# ... rest of your deployment spec
image: my-image:latest Apply your deployment:
kubectl apply -f deployment.yamlMinikube will now use your local Docker image without needing to push it to a registry.
The project demonstrates deploying a simple web application to a Minikube cluster. It includes a Dockerfile that builds an image based on Nginx and copies the application code. A deployment.yaml file defines a Kubernetes Deployment to run three replicas of the application. The instructions guide through building the Docker image, starting Minikube, and deploying the application using kubectl. This setup is suitable for local development and testing, allowing you to run your application in a Kubernetes environment without pushing the image to a registry.
my-project/
├── Dockerfile
└── deployment.yaml
1. Dockerfile:
FROM nginx:latest
# Add your application code here
COPY . /usr/share/nginx/html2. deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-image:latest
ports:
- containerPort: 803. Build and deploy:
Open your terminal and navigate to the my-project directory.
Build the Docker image:
docker build -t my-image:latest .Start Minikube and configure your shell:
minikube start
eval $(minikube docker-env)Apply the deployment:
kubectl apply -f deployment.yamlCheck the deployment status:
kubectl get deploymentsNow, Minikube is running your application using the Docker image built locally without pushing it to any registry. You can access your application through the Minikube IP address and the service port.
Note: This approach is suitable for development and testing purposes. For production environments, it's recommended to push your images to a registry for better management and scalability.
minikube status to check. If it's not running, use minikube start to start it.latest is used in the example, it's good practice to use specific tags for your images (e.g., my-image:v1.0) to avoid confusion and ensure you're deploying the correct version.minikube stop.minikube delete.eval $(minikube docker-env) && docker build .... This eliminates the need to configure your local Docker daemon but might be slower.| Step | Description | Command |
|---|---|---|
| 1. Build Docker Image | Build your Docker image and tag it. | docker build -t my-image:latest . |
| 2. Start Minikube | Start Minikube and configure your shell to use its Docker daemon. |
minikube start eval $(minikube docker-env)
|
| 3. Reference Local Image | In your Kubernetes deployment YAML, reference the locally built image. | image: my-image:latest |
| 4. Deploy to Minikube | Apply your deployment to the Minikube cluster. | kubectl apply -f deployment.yaml |
Summary: This process allows you to deploy a Kubernetes application to Minikube using a Docker image built locally on your machine, without needing to push the image to a container registry.
This guide explained how to streamline your Kubernetes development workflow using Minikube and local Docker images. By configuring your shell to utilize Minikube's Docker daemon, you can directly deploy and test applications without the need for a separate container registry. Remember that while this approach is excellent for development and testing environments, production deployments benefit from the robustness and scalability of dedicated container registries. As you advance in your Kubernetes journey, explore Minikube addons and alternative deployment strategies to further enhance your development process.
Pushing images | minikube | comparing 8 ways to push your image into a minikube cluster.
Using Local Docker Images With Minikube | Baeldung on Ops | Learn three different ways to run local Docker images in Minikube.
How to use local docker images with Minikube? | Better Stack ... | Ship higher-quality software faster. Be the hero of your engineering teams.
How to use local Docker images with Minikube? | by Harold Finch ... | Using local Docker images with Minikube involves a few straightforward steps. Minikube can be configured to use the Docker daemon from the…
How to Use Local Docker Images With Minikube? - GeeksforGeeks | A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
How can I use local Docker images with Minikube? | by Harold Finch ... | Using local Docker images with Minikube is a common requirement during development to speed up the workflow and avoid pushing images to a…
Using local images with minikube - Octopus Deploy | Learn how to deploy locally built Docker images to minikube.