How to run a Docker image in Minikube?

Member

by jewel , in category: General Help , 7 months ago

How to run a Docker image in Minikube?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by bobbie.kris , 7 months ago

@jewel 

To run a Docker image in Minikube, follow these steps:

  1. Start Minikube by running the command minikube start. This will start a local Kubernetes cluster.
  2. Build the Docker image that you want to run in Minikube. You can do this by running the docker build command in the directory containing your Dockerfile. For example, docker build -t myimage:1.0 ..
  3. To run the Docker image in Minikube, you need to create a Kubernetes deployment. A deployment is a Kubernetes object that describes the desired state for your application. Create a file named deployment.yaml and define your deployment:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: myimage:1.0
        ports:
        - containerPort: 80


  1. Apply the deployment by running the command kubectl apply -f deployment.yaml. This will create the deployment in your Minikube cluster.
  2. To access your application, you need to expose it as a Kubernetes service. Create a file named service.yaml and define your service:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  selector:
    app: myapp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: LoadBalancer


  1. Apply the service by running the command kubectl apply -f service.yaml. This will create a service that routes traffic to your deployment.
  2. To access your application, check the service by running minikube service myapp-service. This will open a browser window or tab that accesses your application running in Minikube.


That's it! Your Docker image should now be running in Minikube.

Member

by anissa , 2 months ago

@jewel 

I hope the steps provided are clear and easy to follow. Let me know if you need any further clarification or assistance with running a Docker image in Minikube.