0

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

xetra11
  • 7,671
  • 14
  • 84
  • 159

1 Answers1

0

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

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
  • I actually don't want to install the whole docker-engine to my jenkins environment. Thought therefore I can use `docker-machine` like a thin client which delegates my build process over to my VM#2 and its docker-engine – xetra11 Sep 05 '17 at 19:39
  • `docker-machine` also doesn't give you that option. It is just a automation to manage VM locally or in cloud. It doesn't give you CLI. What it gives you is an SSH option to machine. So which means you get inside the VM and then run commands. You get docker client static binary from this https://download.docker.com/linux/static/stable/x86_64/ and use the docker file directory from this on your jenkins VM – Tarun Lalwani Sep 05 '17 at 19:53
  • It's kinda hard for me to understand that docker-machine can delegate docker commands to a created VM but not to a existing Docker-Host system (also created by a VM in this case) – xetra11 Sep 05 '17 at 20:08
  • 1
    Okie that can be done. Try this `docker-machine create --driver none -url=tcp://VM2:2376 VM2` – Tarun Lalwani Sep 05 '17 at 20:14
  • thanks - now its working besides a SSL issue where I can't call request. But thats another issue! thanks. – xetra11 Sep 05 '17 at 20:25