Table of Contents

Jenkins - Docker Plugin

About

docker plugin

For a docker installation, see Jenkins - Docker Installation

Doc ! https://jenkins.io/doc/book/pipeline/docker#sidecar

Usage

Docker workflow Plugin

The run target also makes reference to file paths on the Docker host, assuming they are where you are running that command.

Step covered by this plugin:

docker.withServer('tcp://host:1234') {
  docker.withRegistry('https://docker.my.com/') {
      semaphore 'wait'
      sh 'echo would be connecting to $DOCKER_HOST'
      echo "image name is ${docker.image('whatever').imageName()}"
  }
}
docker.image('maven:3.3.9-jdk-8').withRun("--entrypoint mvn", "-version") {c ->
    sh "docker logs ${c.id}"
}
node {
  def img = docker.image('httpd:2.4.12')
  def port = img.withRun('-p 12345:80') { c -> c.port(80) }
  echo "container running on ${port}"
}

Example

docker.image(<image>).inside(opts) {
  sh "<command>"
}

# example
docker.image('maven:latest').inside {
    sh 'mvn -version'
}

same as:

sh "docker run --rm -t -e ... <image> <command>"

If you want to override the image's entrypoint you can still use this command:

docker.image("my-image").inside("--entrypoint cat") {}

Docker plugin

https://wiki.jenkins.io/display/JENKINS/Docker+Plugin - Docker plugin allows to use a docker host to dynamically provision build agents, run a single build, then tear-down agent.

Docker plugin works with

Docker plugin is a JCloud Plugin implementation. You'll need to edit to install it and add a new Cloud of type “Docker”.