how to connect docker-machine to my VMs docker-daemon port?

990 views Asked by At

Given these two systems:

  • VM#1 running a jenkins-container which has a installed/working docker-machine
  • VM#2 running a plain ubuntu with docker-engine installed

Both VMs are connected via a networkbridge. I can curl for the Docker-Host on VM#2 out of the jenkins container.

Now I want to tell docker-machine within my jenkins container to build an image (which lies within a jenkins workspace) by using the VM#2 Docker-Host.

All documentation about this only show me drivers like virtualbox or aws but I want to connect to my own created Docker-Host.

What I tried:

In my Jenkins Container I created two Environent Variables:

$ export DOCKER_HOST=tcp://192.168.0.102:2375 
$ export DOCKER_MACHINE_NAME=dev

curl 192.168.0.102:2375 yields {"message":"page not found"}

running docker-machine env dev gives me Host does not exist: "dev"

PS:

I do not want to install docker-engine into my jenkins image. I want to use the thin-client docker-machine to delegate the image build over to VM#2 and nothing more

1

There are 1 answers

5
Tarun Lalwani On BEST ANSWER

Assuming VM#1 is 192.168.33.100 and VM#2 is 192.168.33.101. Both can reach each other. Now you don't need to get docker-machine into picture at all. You can just do below

export DOCKER_HOST=tcp://192.168.33.101:2375/
docker build ....

assuming you opened port 2375 for the docker host. See the below url for detail on this environment variable

https://docs.docker.com/engine/reference/commandline/cli/#environment-variables

Edit-1

If you want to add an exiting machine to docker-machine you can do it using below

docker-machine create --driver none -url=tcp://VM2:2376 VM2

Note: You would also need to setup TLS for this else it would not work with Docker-machine directly because of the open issue https://github.com/docker/machine/issues/1532