Cannot access docker hub after eval of minikube docker env? - docker

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.

Related

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.

How to use docker daemon running on host machine in minikube

I have installed minikube on my laptop, I see that minikube uses docker daemon running within cluster.
Is it possible to run minikube to use the host machine docker daemon?
I tried using
export DOCKER_HOST="tcp://localhost:2376"
ran, minikube start
and, minikube start --docker-env=DOCKER_HOST="tcp://localhost:2376"
Both did not work.
Is it possible to run minikube to use the host machine docker daemon?
No. Minikube runs in a VM, and can't connect to the host's /var/run/docker.sock file. (The setup you show requires a non-default host Docker configuration with significant risk of just outright getting the host rooted, and from the VM's point of view, localhost is the VM.)
You can do the opposite, though, set your local Docker daemon to talk to minikube's Docker daemon
eval $(minikube docker-env)
(Also remember that Kubernetes is designed for multi-host deployments based around immutable images. If you're trying to do live development inside a Kubernetes pod, it is rather complicated and translates poorly to production environments. Use plain Docker, or better still, install a development environment directly on your host. If you're just trying to test out deployment wiring, minikube, or the Kubernetes included in Docker Desktop, or other tools like kind work just fine.)
#David Maze, it's not completely true what you wrote in your answer:
No. Minikube runs in a VM, and can't connect to the host's
/var/run/docker.sock file.
Let's say it can be true only in particular case, so the following question:
Is it possible to run minikube to use the host machine docker daemon?
I would answer: Yes, it is. However typical Minikube instance runs on a separate VM, it is still possible to run it directly on the host. More on that you can read in minikube installation guide in official Kubernetes documentation:
Note: Minikube also supports a --vm-driver=none option that runs the
Kubernetes components on the host and not in a VM. Using this driver
requires Docker and a Linux environment but not a hypervisor. It is
recommended to use the apt installation of docker from Docker, when
using the none driver. The snap installation of docker does not work
with minikube.
#Sunil Gajula, adding following flag:
--vm-driver=none
when running your Minikube instance should actually resolve your problem as it is not set by default to none and it seems the missing element in your attempts to run Minikube on your local machine. So by default it runs in a VM, using one of the available hypervisors ( if you don't specify above mentioned flag).
I got this working on my mac OS.
And I use fish:
##install docker-cli
#brew install docker
#brew install minikube hyperkit
## run minikube without kubernetes enabled
#minikube start --memory 6144 --cpus 4 --docker-opt=bip=172.17.42.1/16 --no-kubernetes
# minikube -p minikube docker-env | source (put the result into config and source it)for bash/zsh: minikube docker-env
And if you want to run minikube k8s cluster:
you can:
# minikube start --addons=registry --cni=calico --driver=hyperkit --cpus=8 --memory=8g (or some simple command)
You may need to install docker-machine-driver-hyperkit with install command.
With everything ok, you can use docker-cli to interact docer daemon in minikube.

Why docker-daemon is not accessible in minikube VM?

I have installed minikube and started it with it's default virtual machine so basically started the minikube with minikube start. In minikube vm which i have accessed through minikube ssh i am trying to build my dockerfile after mounting the local file system but it's showing error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I checked the ActiveState of docker through systemctl show --property ActiveState docker and it's showing failed but the docker version is showing me all the normal details like version built etc.
This is the statement that i am trying to execute : $ sudo docker build --file=Dockerfile --tag=demo-backend:latest --rm=true .
Should i install docker seperatley and if not how should access docker in VM which is already present in my system
It looks like somehow docker has not started properly.
Please try to execute sudo systemctl start docker and let me know if that was the issue.
EDIT:
Adding more info from the comments in order to supplement the answer:
I had to set the docker environment variable to local instance of
docker running in minikube through this command: eval $(minikube
docker-env) and then restart the docker and all of this has to done in
the same shell in which i aim to access the docker otherwise it does
not works. this made me acces the docker from minikube – rehan

What does minikube docker-env mean?

In the Kubernetes minikube tutorial there is this command to use Minikube Docker daemon :
$ eval $(minikube docker-env)
What exactly does this command do, that is, what exactly does minikube docker-env mean?
The command minikube docker-env returns a set of Bash environment variable exports to configure your local environment to re-use the Docker daemon inside the Minikube instance.
Passing this output through eval causes bash to evaluate these exports and put them into effect.
You can review the specific commands which will be executed in your shell by omitting the evaluation step and running minikube docker-env directly. However, this will not perform the configuration – the output needs to be evaluated for that.
This is a workflow optimization intended to improve your experience with building and running Docker images which you can run inside the minikube environment. It is not mandatory that you re-use minikube's Docker daemon to use minikube effectively, but doing so will significantly improve the speed of your code-build-test cycle.
In a normal workflow, you would have a separate Docker registry on your host machine to that in minikube, which necessitates the following process to build and run a Docker image inside minikube:
Build the Docker image on the host machine.
Re-tag the built image in your local machine's image registry with a remote registry or that of the minikube instance.
Push the image to the remote registry or minikube.
(If using a remote registry) Configure minikube with the appropriate permissions to pull images from the registry.
Set up your deployment in minikube to use the image.
By re-using the Docker registry inside Minikube, this becomes:
Build the Docker image using Minikube's Docker instance. This pushes the image to Minikube's Docker registry.
Set up your deployment in minikube to use the image.
More details of the purpose can be found in the minikube docs.
Try to run minikube docker-env
You will see some environment variables are mentioned there :)
These variables will help your docker CLI (where you write docker commands) to connect with docker daemon in the VM created by minikube !
Now, to connect your Docker CLI to the docker daemon inside the VM you need to run : eval $(minikube docker-env)
This will temporarily(for that terminal) connect CLI to docker daemon inside the VM :)
Now, try to do docker ps , you can see all the containers created inside the VM (will be shown only if you have done some work in k8's cluster)
This is all possible due to those environment variables by docker-env
One way to figure out what $ eval $(minikube docker-env) does is to understand that we want to build a docker image in our local machine and then deploy them to the minikube environment.
This command as others have explained makes it easier to do so.
It is telling minikube to use the configs returned from minikube docker-env
You can then build your docker image locally and be able to access it within the minikube env
Once you're done building you can unset docker env i.e. disconnect your minikube env by unsetting these docker configs if you run minikube docker-env --unset
Without setting your docker configs to minikube env it'll be a bit tedious to build your image locally and run it in a container in your minikube env.
If you have minikube running you can ssh into the env and see all docker images running within it.
You should run this command after running 'minikube start'
eval $(minikube docker-env) this command let you Connect your cli tool to docker-env of Kubernetes cluster

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