Jenkins trigger on-demand slaves in dockers

I’m looking for a way to run Jenkins jobs/build inside Jenkins slaves, dynamically (on-demand) started docker. Attaching schema for visual understanding.
What I’m actually looking for and my flow looks like:

1) Triggering Jenkins job (manually/git/gerrit)
2) Jenkins master (running in docker) starts slave machine docker (and pass script/instructions of the build)
3) Build is running on Jenkins slave (or slaves if parallel/pipeline)
4) Result returned to Jenkins master
5) Jenkins slave docker stops

  • Boot2Docker: Connect to container over LAN
  • installing cPickle with python 3.5
  • Updating docker registry in ubuntu 14.0
  • Running a node app as a non root user in docker
  • Docker build on apt-get update fails
  • Heroku-docker not working on osx
  • Jenkins Flow

    Is it possible to do it this way?

  • How could I execute 'apt-get install' on docker ubuntu contain?
  • Running multiple applications in one docker container
  • Using absolute path with docker run command not working
  • Getting User name + password to docker container
  • Build with maven in docker throw {}->unix://localhost:80: No such file or director
  • Pull Image with Docker on Windows 10 : “failed to register layer …Denied Access”
  • 2 Solutions collect form web for “Jenkins trigger on-demand slaves in dockers”

    1. Docker slave image creation steps like installing openssh, user creation, mentioned in the below link. Install docker plugin from the below link.

      Click here!

    2. Go to jenkins global configuration, Under cloud headings, docker configuration will be there, enter docker host url with port number, credential not required. give some values for connection timeout & read timeout.

    3. Under docker template – Enter the docker image name which we created in the point number 1.

    4. Set Label number (Give this label name during Jenkins job creation and restrict to this slave name),

    5. Select the usage option – > only build job with label restriction.

    6. No of executor -> minimum 1. Select launch method as ssh, enter the user credential to login, which we created in docker image in the step number 1.

    create a job restrict to docker slave label, run, ondemand it wil spun up container.

    Use this plugin: https://wiki.jenkins-ci.org/display/JENKINS/Yet+Another+Docker+Plugin

    After instalation (it requires Java 1.8) naviaget to configuration. There are two steps:

    1. configure docker “cloud”
    2. add “instances” (docker images) you want to run the build on

    Every image should have label assigned – use this label in you job configuration to tell Jenkins explicitlyon which node the job should be run

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.