Run Jenkins Job in a container

I have several Jenkins jobs and several Jenkins slave nodes (physical machines). These slaves are all running docker 1.12.1. I would like for any of these jobs to run on any of these slaves. Since these jobs have different environment requirements, I thought that I could create docker images for each of the different environments and then “within” the job, specify which container the job would run in.

Is this possible? i.e. to specify within these jobs a specific docker container that I would like these jobs to run in? At the end of the job, the containers would be destroyed and only the artifacts and reports would remain.

  • Amazon Container Registry Only with ECS?
  • Linking django and mysql containers using docker-compose
  • Is it possible to assign a static IP adress to a docker container after it's creation?
  • docker command not found even though installed with apt-get
  • How to forward Docker for Mac to X11?
  • Docker and systemd - service stopping after 10 seconds
  • There are several docker plugins that exist in Jenkins but I have yet found one that does exactly what I want.

  • ERROR 1582 (42000) Incorrect parameter count in the call to native function 'FROM_UNIXTIME'
  • How to create a Dockerfile for cassandra (or any database) that includes a schema?
  • Can not install package within docker debian:jessie
  • Connecting inside container at docker environment using JSCH
  • How to install docker on CentOS 7?
  • building in docker using buildpack-deps, but dependencies don't seem to be installed?
  • 2 Solutions collect form web for “Run Jenkins Job in a container”

    Of course, the answer is Yes, this is possible.

    Given the broad type of question, I can only give pointers.

    jenkins-pipeline offers a nice way to describe your pipelines as code. The docker plugin also integrates with that, so that you can run your jobs within a container, e.g.

    // select a slave based on the label 'docker'
    node('docker') {
      stage "Run in container (e.g. the php-7)"
      docker.image('php:7').inside {
        // run your command
        sh "phpunit"

    There are couple of resources out there regarding jenkins-pipelinedocker that will get you started.

    I found the plugin I was looking for.

    This will do what I want. It will allow me to run my jobs in a container. So far, it is working well.

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