Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using docker plugin on jenkins -

Tags:

docker

jenkins

I'm trying to use the docker plugin on Jenkins to run an instance of an existing container. Docker version 1.6.0, build 4749651

I've chosen "create container" Entered the image id for the image name, and tried a host http://172.16.42.43:4243 and also tried an empty host. I keep getting this error:

ERROR: Build step failed with exception
java.lang.NullPointerException: uri was not specified
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:204)
    at com.github.dockerjava.core.DockerClientConfig$DockerClientConfigBuilder.withUri(DockerClientConfig.java:406)
    at org.jenkinsci.plugins.dockerbuildstep.DockerBuilder$DescriptorImpl.createDockerClient(DockerBuilder.java:123)
    at org.jenkinsci.plugins.dockerbuildstep.DockerBuilder$DescriptorImpl.getDockerClient(DockerBuilder.java:201)
    at org.jenkinsci.plugins.dockerbuildstep.DockerBuilder.perform(DockerBuilder.java:71)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
    at hudson.model.Build$BuildExecution.build(Build.java:205)
    at hudson.model.Build$BuildExecution.doRun(Build.java:162)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
    at hudson.model.Run.execute(Run.java:1744)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:374)
Build step 'Execute Docker container' marked build as failure

Can someone tell me how to fix it? Also, if anyone has used this plugin before, please let me know if this has ever worked.

Also tried the "Execute docker container"->start containers with the container id specified resulting in the same error.

Another approach: I tried using the Execute shell plug in and I'm getting this error:

+ docker start d023eec1ff34
Post http:///var/run/docker.sock/v1.18/containers/d023eec1ff34/start: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?
time="2015-05-05T10:26:34-07:00" level=fatal msg="Error: failed to start one or more containers"

If I just go to the terminal, switch to jenkins user and run the docker start command, it works fine. If someone know how to fix it this way, that would be great as well.

like image 886
max Avatar asked May 05 '15 07:05

max


2 Answers

Assuming Docker is running on the same machine, make sure to run Docker with:

-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock

Then go to Manage Jenkins > Configuration > Configure System then scroll down to Docker Builder and in the Docker server REST url enter http://localhost:4243

Edited: I had originally told Docker to listen on 0.0.0.0 which binds to all IP addresses and could allow connections from the outside if your Firewall lets the traffic through. So I updated it to bind to the loopback address instead. Also, the current version of the documentation recommends a different port but since you specify the port manually any port will do.

like image 113
Andrew Curioso Avatar answered Nov 04 '22 08:11

Andrew Curioso


You need to give Jenkins user permissions to use docker, buy adding it to docker group, run

sudo usermod -a -G docker jenkins
like image 32
moshe beeri Avatar answered Nov 04 '22 07:11

moshe beeri