how to use local images in kubernetes using minikube - docker

I have just started working on k8s and I am doing some stuff locally,
I have a image created using docker desktop. Now, I want this image to be used within my minikube's VM environment. I want to create a deployment using kubectl create deployment hello-minikube --image=my_local_image_name. Going through docs, and as per my understanding, it tells us how docker desktop can be used to interact with the minikube's in-built docker demon.
Following the instructions,
Running docker images gives me images within minikube's docker.
But, in my case I want the other way around.
How can I do that ?
Secondly, as a add-on how can I store images within minikube's VM's docker ?

Docker Desktop and Docker from Minikube are two separate Docker Engines. That is why they don't share the Docker image registry.
So you have the following options:
Use Kubernetes from Docker Desktop instead of Minikube (Docker Desktop comes with Kubernetes cluster built-in).
Build your Docker image with Docker Engine from Minikube (instead of Docker Desktop).
Use external Docker registry (you can use Docker Hub or set up your own registry)

Running docker images gives me images within minikube's docker.
When you have this behaviour in your shell, rebuild your docker image.
It will use Docker from Minikube and store your image into Minikube's Docker registry

Related

Pointing powershell to correct Docker

I am new to Docker and MiniKube.
On my Windows laptop I have installed Docker Desktop and MiniKube.
I created two nodes in MiniKube and they are up and running.
I have been using Powershell with images and containers with Docker Desktop with no issues.
Now I realize that Minikube is using it's own installation of Docker and I cannot see the containers created by MiniKube in Powershell.
How do I get Powershell to point to Docker used by MiniKube?
How do I reverse that change to work again with Docker Desktop?

How to use a local image as service in a docker-machine

I want to use a locally build docker image in my docker-machine
I have a swarm cluster set up with docker-machine and like to use locally build docker image. after ssh into a one node with docker-machine ssh manager
I want to start a service with a locally build image such as
docker service create --name=database --publish=3306:3306 <localDataBaseImage>
How can this be achieved
You need to push the image to docker hub/ local docker registry and use that image while creating containers in docker machine.
if you have the image in docker hub, you need to perform docker login in the docker-machine
if you have the image in local registry, create docker-machine with insecure-registries option pointing to the url of your registry.

How do I access minikube docker daemon on Windows?

I installed minikube and now I want to create my docker containers, but how do I run the docker commands? I tried the following from command prompt
But it does not recognize docker as a command.
Also I tried from PowerShell with the same result, docker not recognized.
I currently only have minikube installed on my workstation because I was given the impression from comments to a previous question that I did not need Docker Desktop (see Unable to connect to running docker containers (minikube docker daemon))
In this SO question there is an answer that will show you 3 ways how to make Minikube and Docker work on Windows:
Scenarios are like this:
1) Use Docker, and minikube with Hyper-V (you will find instruction in
an answer above) Enable Hyper-V, install Docker, use minikube with
arguments minikube start --vm-driver hyperv --hyperv-virtual-switch
"<created Hyper-V switch name>" In the same time you will be able to
interact with Docker in normal way. Use kubectl/minikube commands for
your Kubernetes cluster and Docker commands for Docker. 2) Use
VirtualBox for Kubernetes and Docker toolbox for Docker minikube
start --vm-driver=virtualbox
3) Use Docker for Windows and Kubernetes in Docker
I believe this will solve your issue. Please, let me know if that helped.

Cannot access docker hub after eval of minikube docker env?

I am really confused, I had being learning kubernetes with minikube creating services and other things.
The problem comes in the following shape:
I run the following commands after a fresh install of minikube:
eval $(minikube docker-env)
The reason is because I want to get an image from my computer to be used with minikube. My understanding is that with this command I am in the same context for minikube and docker, so I can access my local images. "Please correct me if I am wrong here".
minikube start
So I get up and running the cluster, and ready to start creating things.
I want to pull the following container:
docker pull nginx/nginx-ingress
Because I want to try an ingress controller to work with my services.
But then I get this weird message:
Using default tag: latest
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon at tcp://192.168.99.101:2376. Is the docker daemon running?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon at tcp://192.168.99.101:2376. Is the docker daemon running?
I run:
docker ps
And no results with a hang out.
I go to another terminal, I run the docker ps and it works like a charm.
Please if someone can bring some light to me of the impact of the command:
eval $(minikube docker-env)
And if you know why in my current Term with minikube running cannot access to my docker machine would help a lot.
minikube starts a dedicated virtual machine as a single-node Kubernetes cluster. If you have other Docker environments (a separate Docker Machine VM, the Docker Toolbox VM, the Docker for Mac or Docker for Windows environments, or a Linux-native Docker) these are separate from the Docker in the VM. You can't share images or containers between these environments.
If you have private images that aren't published to a registry, you'll have to re-docker build them when you switch to the Minikube environment. You otherwise don't specifically have to docker pull things that you're using, when you reference them in a Kubernetes pod spec Kubernetes will pull them for you.

Use my local docker registry instead of minikube's

I am using minikube as my kubernetes cluster. I would like to know if there is a way to redirect minikube's docker environnement to my local environnement instead of doing the opposite with the following command:
eval $(minikube docker-env)
The problem when using the latest is that when I build a image it is destroyed whenever minikube is deleted and has to be rebuilt everytime which takes 30-40 minutes.
If you want to use your host's docker for minicube, you can just do
minikube start --vm-driver=none
It does not requires any VMs, works fast and use your host's docker. But prefer docker version 1.13

Resources