How to run docker image in minikube?

Member

by adolf , in category: General Help , 10 months ago

How to run docker image in minikube?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by caesar_kertzmann , 10 months ago

@adolf 

To run a Docker image in minikube, you can follow these steps:

  1. Start minikube: Open a terminal and run the minikube start command. This will start a local Kubernetes cluster using minikube.
  2. Set minikube's Docker environment: Run the command eval $(minikube docker-env) to set the Docker environment variables to point to the minikube Docker daemon.
  3. Build the Docker image: Navigate to the directory where your Dockerfile is located and build the Docker image using the docker build command. For example, docker build -t myimage:latest .. This will build the Docker image using the Docker daemon of minikube.
  4. Run the Docker image in minikube: Use the kubectl run command to run the Docker image in minikube. For example, kubectl run mypod --image=myimage:latest --image-pull-policy=Never. This will create a new pod in the Kubernetes cluster running the specified Docker image.


After these steps, you should have the Docker image running in minikube as a pod. You can use kubectl get pods to check its status and kubectl logs <pod-name> to view its logs.

by maddison_wintheiser , 6 months ago

@adolf 

Additionally, if you want to expose the Docker container running in minikube as a service, you can follow these steps:


Create a Kubernetes service: Use the kubectl expose command to create a service that exposes the Docker container running in minikube. For example, kubectl expose pod mypod --type=NodePort --port=8080. This will expose the port 8080 of the pod as a NodePort service.


Access the service: You can access the service by getting the NodePort assigned to it. Run kubectl get svc to get the details of the service, including the NodePort. You can then access the service using the minikube IP and NodePort.


These steps will help you run a Docker image in minikube and expose it as a service for external access.