I use vagrant to manage VirtualBox and I want to build a cluster using Docker Swarm.
When I run the command docker node ls it shows the same hostname. Also if I run the service, they are run and shutdown immediately and run and shutdown.
Here is the vagrant file.
Here is the docker swarm result show.
I suggest installing docker-machine and then use the following script to install a swarm
Troubles using docker-machine to setup Swarm
Under the hood it still uses Virtualbox, just a more docker friendly way compared to vagrant.
Might be caused by this issue of changing the hostname before or after docker-engine:
https://github.com/docker/docker/issues/27173
After I rebooted my VM, the HOSTNAME column was correct.
Related
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.
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.
When I use docker-machine in a Windows environment (installed with docker-toolbox), every docker run command uses that docker-machine as the docker daemon.
However, when I use docker-machine in a Linux environment, which has native docker daemon installed along with docker-machine, docker run command uses native docker daemon even if there is a running docker-machine instance.
Questions are:
How does docker run command decide which daemon to use?
Are there any method to list running containers on a docker-machine instance?
For the second one, I know I can SSH to the docker-machine instance and query docker ps in it, but I want check it from outside the instance.
Thanks in advance.
The Docker Machine stack works by firing up a VM, and then setting the DOCKER_HOST environment variable to point at it. In particular, it also does the required setup to TLS-encrypt the connection and to set up a TLS client certificate to authenticate the caller. (Without this setup, a remote DOCKER_HOST is extremely dangerous.)
So: docker run and every other Docker command uses the DOCKER_HOST environment variable to decide where to run things. If DOCKER_HOST points at a Docker Machine VM, docker ps will list the containers there; you won’t usually need to docker-machine ssh (though it’s a useful tool when you really need it).
On a native Linux host it’s far easier to just directly use a local Docker daemon. If you do have both a local daemon and a docker-machine VM, you can
# switch to the Docker Machine VM
eval $(docker-machine env default)
# switch back to the host Docker
eval $(docker-machine env -u)
I am running minikube using the instructions at
https://kubernetes.io/docs/tutorials/hello-minikube/
I started minikube:
$ minikube start --vm-driver=hyperkit
and verified that it is successfully running.
I am running 'Docker Community Edition' version 18.06.1-ce-mac73.
$ minikube ssh
is working fine.
However when I do
$ docker ps
on my mac os host, it doesn't show any containers. However, when I do
$ docker ps
after doing minikube ssh, I see about 20 containers.
So, where are the docker containers really running? Why does docker ps not show any containers on my mac?
Thank you.
You can use the following command to configure your Docker Host address:
eval $(minikube docker-env)
Then, when you run docker ps, you should see your containers. Read more here.
Docker containers are not running on your MAC host.
They are running on a VM where you can do minikube ssh to that VM.
The docker ps shows the containers in there inside that VM.
That's expected because you are using hyperkit driver to work as a hypervisor & launch lightweight virtual machines. Think of it as virtualbox launching VMs for you & complete k8s cluster is deployed into those VMs, all of them are well integrated.
Use below to get your virtual machine address or the server where these containers are actually running -
$ minikube ip
Ref -
https://github.com/moby/hyperkit
Since I can't add a comment:
To revert the change in your shell, use
eval $(minikube docker-env -u)
as answered here: How do I undo the command $ eval "$(docker-machine env blog)"
I used docker with docker-machine ( can access container server by 192.168.99.100 ). I would like not to use docker-machine. so I can directly access my container by localhost (127.0.0.1). I shut down docker-machine (docker-machine stop) and tried to build image and container, but It said 'no daemon'. how should I completely shut down docker-machine and use local docker?
I think what you want is unset all docker-machine environment variables to use you host Docker daemon. This can be achieved with this command.
eval $(docker-machine env -u)
There are two different installs for docker on Mac. Both use a VM running Linux under the covers.
The older method includes docker toolbox and docker machine to manage the VM in virtualbox. When you use docker machine to stop this VM, the docker commands have no host to run on and will error out as you've seen.
The newer install uses xhyve to run the VM and various other tricks to make it appear seamless. This is a completely different install that you download and run from Docker, and it requires your Mac be at least version 10.10.3 with Yosemite.
See this install page for more details: https://store.docker.com/editions/community/docker-ce-desktop-mac?tab=description