lvthillo
lvthillo

Reputation: 30723

Use docker build step plugin in Jenkins docker container

I have a jenkins server inside a docker container:

I've edited the base image so I'm able to mount the docker sockets to my container and use the sockets as jenkins user.

docker run -d -u jenkins --name jenkins \
  -p 50000:50000 \
  -p 8080:8080 \
  --volumes-from jenkins-volume \ 
  --restart=always \
  -v /var/run/docker.sock:/var/run/docker.sock \ 
  test/jenkins:1.0

So I'm able to run commands such as docker version and docker ps in my jenkins container (in a shell).

Now I've installed the docker build step plugin.

My question is how can I have to use and configure this plugin?

In the global configuration I see:

So I don't know how to configure this.

When I just try to perform a docker command using the plugin in a Jenkins Job I get an error; I'm not able to save the configuration of the docker command inside my job and I see the following error in my logs on jenkins:

Error while serving http://ip:8080/job/docker-test/configSubmit
java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor648.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
...
Caused by: javax.servlet.ServletException: This page expects a form submission but had only {}

How can I configure this plugin inside a jenkins-docker container in which the docker sockets are mounted?

Upvotes: 4

Views: 3975

Answers (1)

Gi Mbu
Gi Mbu

Reputation: 21

  1. Change docker daemon from unix socket to tcp/2375
  2. In the Jenkins / Settings / Docker Builder / Docker URL section add docker rest-url on port 2375 (even if TEST doesnt work)

Put just 172.17.0.1:2375 (where 172.17.0.1 is the host running the docker daemon)

Upvotes: 1

Related Questions