3

I need to run docker commands from jenkins which is installed as a container on docker. My local setup is on an OSX and I use boot2docker to virtualize the docker machine.

I have installed jenkins on docker by simply docker run -d -p 8080:8080 --name jenkins jenkins and it is running fine.

On jenkins I have installed "Docker plugin" https://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin which needs DOCKER URL in order to access docker api.

When boot2docker starts i get the following: DOCKER_HOST=tcp://192.168.59.103:2376, so I assume docker api is running on that host/por?

On jenkins I set up the DOCKER URL field as http://192.168.59.103:2376 but I get the following error "shaded.org.apache.http.client.ClientProtocolException".

It seems that the container cannot access boot2docker docker server. Maybe I'm missing something but I am not able to figure out what is the correct ip/port I have to use.

Update: More Details

This is what I get when I start boot2docker:

bash-3.2$ unset DYLD_LIBRARY_PATH ; unset LD_LIBRARY_PATH
bash-3.2$ mkdir -p ~/.boot2docker
bash-3.2$ if [ ! -f ~/.boot2docker/boot2docker.iso ]; then cp /usr/local/share/boot2docker/boot2docker.iso ~/.boot2docker/ ; fi
bash-3.2$ /usr/local/bin/boot2docker init 

  WARNING: The 'boot2docker' command line interface is officially deprecated.

  Please switch to Docker Machine (https://docs.docker.com/machine/) ASAP.

  Docker Toolbox (https://docker.com/toolbox) is the recommended install method.

Virtual machine boot2docker-vm already exists
bash-3.2$ /usr/local/bin/boot2docker up 

  WARNING: The 'boot2docker' command line interface is officially deprecated.

  Please switch to Docker Machine (https://docs.docker.com/machine/) ASAP.

  Docker Toolbox (https://docker.com/toolbox) is the recommended install method.

Waiting for VM and Docker daemon to start...
...............oooooooo
Started.
Writing /Users/local/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/local/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/local/.boot2docker/certs/boot2docker-vm/key.pem

To connect the Docker client to the Docker daemon, please set:
    export DOCKER_TLS_VERIFY=1
    export DOCKER_HOST=tcp://192.168.59.103:2376
    export DOCKER_CERT_PATH=/Users/local/.boot2docker/certs/boot2docker-vm

Or run: `eval "$(boot2docker shellinit)"`

bash-3.2$ $(/usr/local/bin/boot2docker shellinit)
Writing /Users/local/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/local/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/local/.boot2docker/certs/boot2docker-vm/key.pem
bash-3.2$ docker version
Client:
 Version:      1.8.0
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   0d03096
 Built:        Tue Aug 11 17:17:40 UTC 2015
 OS/Arch:      darwin/amd64

Server:
 Version:      1.8.0
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   0d03096
 Built:        Tue Aug 11 17:17:40 UTC 2015
 OS/Arch:      linux/amd64

Here goes the jenkins configuration for the Cloud:

Docker configuration in jenkins

ddelizia
  • 1,571
  • 5
  • 30
  • 54
  • 2
    When I'm running jenkins on linux, I'm mapping docker socket (/var/run/docker.sock) into container via "-v /var/run/docker.sock:/var/run/docker.sock" option. Not sure how exactly boot2docker working, but if it doing mappings to boot2docker vm filesystem it should work. – ISanych Aug 19 '15 at 15:29

3 Answers3

1

As @ISanych suggests you can simply do -v /var/run/docker.sock:/var/run/docker.sock and it will also magically work on boot2docker. No need to define DOCKER_URL.

You might also find --net=host useful if need to access the ports of the started containers.

Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27
  • I did what you said starting the container in the following way ```docker run -d -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock --net=host --name jenkins jenkins```but no luck, I am still not able to connect to the cloud ```shaded.org.apache.http.client.ClientProtocolException``` (if I dont use DOCKER URL in the jenkins configuration then I'm not able to test) – ddelizia Aug 20 '15 at 09:58
  • 1. Which cloud are you trying to connect to? 2. What do you use as `DOCKER_URL` now? – Mykola Gurov Aug 20 '15 at 19:24
  • I just added more informations in the problem description – ddelizia Aug 24 '15 at 14:34
  • Could you try setting DOCKER URL to `unix:///var/run/docker.sock` (in combination with the `-v /var/run/docker.sock:/var/run/docker.sock` to run the container of course) – Mykola Gurov Aug 24 '15 at 15:28
  • @MykolaGurov where this -v /var/run/docker.sock:/var/run/docker.sock need to provided??in docker url.Could you plese suggest how to give this config in docker url – rselvaganesh Apr 11 '17 at 12:53
1

I ran into exact same problem with my Jenkins docker plugin. Docker uses tls by default but docker plugin only supports http. What I did is disabling TLS verification on the docker machine. My docker machine is an Ubuntu so the docker conf file is under /etc/default/docker. Inside the conf file, you can disable TLS by adding

--tls=false 

in DOCKER_OPTS. Something like:

DOCKER_OPTS='-H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --tls=false'
alex Lai
  • 66
  • 4
-2

This should probably be a comment on the previous answer, but that does not seem possible. This is just a note to remind folks that listening on 0.0.0.0 means listening on whatever publicly routable interfaces might be connected to any physical or virtual network interface configured on your system. Prudence suggests limiting your exposure to only an internal network, less likely to encounter hostile forces with ill intent.

Hugh Esco
  • 67
  • 1
  • 6