How to use local docker images with Minikube?

Better Stack Team
Updated on October 5, 2023

To use local Docker images with Minikube, you can follow these steps:

  1. Start the Minikube cluster by running the following command:

     
    minikube start
    
  2. Build the Docker image: Build the Docker image using the docker build command. For example, to build an image from a Dockerfile in the current directory, run the following command:

     
    docker build -t my-image .
    

    This will create a Docker image with the tag my-image.

  3. Load the image into Minikube: Load the Docker image into Minikube by running the following command:

     
    minikube image load my-image
    

    This will load the my-image Docker image into the Minikube Docker daemon.

  4. Use the image in a Kubernetes deployment: You can now use the my-image Docker image in a Kubernetes deployment by specifying the image name in the deployment manifest. For example:

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

    This will create a deployment with one replica and a container named my-container, which uses the my-image Docker image.