How to run minikube inside a docker container?

by aliya.yundt , in category: General Help , 5 months ago

How to run minikube inside a docker container?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by adolf , 5 months ago

@aliya.yundt 

To run minikube inside a docker container, you can follow these steps:

  1. Install Docker: Install Docker on your machine if you haven't already done so. You can download it from the official Docker website.
  2. Install kubectl: Install kubectl, the Kubernetes command-line tool, on your machine.
  3. Build Docker image: Create a Dockerfile with the following content to build your Docker image:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
FROM ubuntu:latest

# Install dependencies
RUN apt-get update &&     apt-get install -y curl wget vim

# Install minikube
RUN curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 &&     chmod +x minikube-linux-amd64 &&     mv minikube-linux-amd64 /usr/local/bin/minikube

# Set environment variables
ENV MINIKUBE_WANTUPDATENOTIFICATION=false
ENV MINIKUBE_WANTREPORTERRORPROMPT=false
ENV MINIKUBE_HOME=/root
ENV CHANGE_MINIKUBE_NONE_USER=true

# Start minikube
CMD ["minikube", "start", "--driver=docker"]


Save the file as Dockerfile.

  1. Build the Docker image: Open a terminal and navigate to the folder containing the Dockerfile. Run the following command to build your Docker image:
1
docker build -t minikube-docker .


Wait for the image to build.

  1. Run the Docker container: Run the following command to start the minikube inside a Docker container:
1
docker run -it --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro minikube-docker


This command starts the Docker container with privileged access and mounts necessary paths for managing cgroups.

  1. Verify installation: Once the container starts, you will be inside the container's shell. Run the following command to verify the installation:
1
kubectl version


If everything is set up correctly, you should see the version information for both the Client and Server.


That's it! You have successfully set up minikube inside a Docker container. You can now interact with the Kubernetes cluster running inside the Docker container using kubectl.

by alysson_lynch , 17 days ago

@aliya.yundt 

Please note that running Minikube inside a Docker container within a Docker container (nested containers) may not work as expected due to limitations and security concerns. It is recommended to run Minikube directly on your host machine for better performance and compatibility.