It would be nice if it were possible to run steps inside a reusable docker container. The intention is to have different, clean build environments for every build, where dependencies could be installed without affecting the build host or other builds.

      Further it would be nice if such a container would "live" throughout the whole build process and the user could decide which step to run inside it and which not (e.g. steps like sonar testing does not need to run inside the container, or maybe these tests should run in a dedicated sonar-container).

      The "oki-docki" plugin uses "docker exec" to run commands inside a container which is a nice way of implementation. Accessing such a container from within the workflow plugin would be nice.
      The "docker" plugin has dependencies on the docker image (e.g. it needs an installed jre, sshd , etc) which is not nice.

          [JENKINS-26178] Ability to run docker-exec etc. from a workflow

          Jesse Glick added a comment -

          The Docker Build Step plugin is the closest match I can find to what you are talking about. (It does not sound like it currently allows docker exec commands, but I think that would be a natural addition.) If made to implement SimpleBuildStep (merely newer core dep) it could be used as is from Workflow.

          Or there could be dedicated workflow steps (workflow-step-api dep) if that is more helpful; for example a block-scoped step could be defined which uses LauncherDecorator to wrap all nested commands in docker exec.

          The Docker plugin should already work with Workflow, but yes it assumes that the image has a JRE and SSHD since it runs the slave agent inside the image, rather than assuming a separate slave.

          Jesse Glick added a comment - The Docker Build Step plugin is the closest match I can find to what you are talking about. (It does not sound like it currently allows docker exec commands, but I think that would be a natural addition.) If made to implement SimpleBuildStep (merely newer core dep) it could be used as is from Workflow. Or there could be dedicated workflow steps ( workflow-step-api dep) if that is more helpful; for example a block-scoped step could be defined which uses LauncherDecorator to wrap all nested commands in docker exec . The Docker plugin should already work with Workflow, but yes it assumes that the image has a JRE and SSHD since it runs the slave agent inside the image, rather than assuming a separate slave.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          COMPATIBILITY.md
          http://jenkins-ci.org/commit/workflow-plugin/0d888e2678a414243a8a0fc100f5ee4650ca02a2
          Log:
          JENKINS-26178 Noting.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: COMPATIBILITY.md http://jenkins-ci.org/commit/workflow-plugin/0d888e2678a414243a8a0fc100f5ee4650ca02a2 Log: JENKINS-26178 Noting.

          Code changed in jenkins
          User: Vojtech Juranek
          Path:
          src/main/java/org/jenkinsci/plugins/dockerbuildstep/cmd/ExecCreateCommand.java
          src/main/java/org/jenkinsci/plugins/dockerbuildstep/cmd/ExecStartCommand.java
          src/main/resources/org/jenkinsci/plugins/dockerbuildstep/cmd/ExecCreateCommand/config-detail.jelly
          src/main/resources/org/jenkinsci/plugins/dockerbuildstep/cmd/ExecStartCommand/config-detail.jelly
          http://jenkins-ci.org/commit/docker-build-step-plugin/8b548ee6b99cd4cc21998bbb0415b28d2c8b35ea
          Log:
          JENKINS-26178 Add create exec and start exec commands

          Compare: https://github.com/jenkinsci/docker-build-step-plugin/compare/9b0d18e33015...8b548ee6b99c

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Vojtech Juranek Path: src/main/java/org/jenkinsci/plugins/dockerbuildstep/cmd/ExecCreateCommand.java src/main/java/org/jenkinsci/plugins/dockerbuildstep/cmd/ExecStartCommand.java src/main/resources/org/jenkinsci/plugins/dockerbuildstep/cmd/ExecCreateCommand/config-detail.jelly src/main/resources/org/jenkinsci/plugins/dockerbuildstep/cmd/ExecStartCommand/config-detail.jelly http://jenkins-ci.org/commit/docker-build-step-plugin/8b548ee6b99cd4cc21998bbb0415b28d2c8b35ea Log: JENKINS-26178 Add create exec and start exec commands Compare: https://github.com/jenkinsci/docker-build-step-plugin/compare/9b0d18e33015...8b548ee6b99c

          Jesse Glick added a comment -

          The CloudBees Docker Workflow plugin offers this feature.

          Jesse Glick added a comment - The CloudBees Docker Workflow plugin offers this feature.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          COMPATIBILITY.md
          http://jenkins-ci.org/commit/workflow-plugin/6361ce7597b9579aa5725e614193b47d82fc7b90
          Log:
          JENKINS-26178 docker-workflow plugin is where people would more likely go for this feature.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: COMPATIBILITY.md http://jenkins-ci.org/commit/workflow-plugin/6361ce7597b9579aa5725e614193b47d82fc7b90 Log: JENKINS-26178 docker-workflow plugin is where people would more likely go for this feature.

          James Hogarth added a comment -

          This was marked resolved but then after that moved to docker workflow where there is no capability to use exec on a running container ...

          Since docker.inside does the volume mounting behaviour and overrides ENTRYPOINT to cat it messes with things like testing a service that relies on systemd

          It should be possible to have a workflow similar to:

          docker.build('customdocker')
          docker.image('customdocker').withRun {
          it.exec("bash -c 'ps -efc ; id -a ; hostname'")
          }

          This would have Container.exec() as a method to run docker exec against the container object.

          As an alternative to extending the container object (which would need the it in the closure above being a little messy, but does mean it'd work with docker.run() ) adding exec alongside inside which runs each step via exec instead and doesn't override the entrypoint would be in line with other use.

          James Hogarth added a comment - This was marked resolved but then after that moved to docker workflow where there is no capability to use exec on a running container ... Since docker.inside does the volume mounting behaviour and overrides ENTRYPOINT to cat it messes with things like testing a service that relies on systemd It should be possible to have a workflow similar to: docker.build('customdocker') docker.image('customdocker').withRun { it.exec("bash -c 'ps -efc ; id -a ; hostname'") } This would have Container.exec() as a method to run docker exec against the container object. As an alternative to extending the container object (which would need the it in the closure above being a little messy, but does mean it'd work with docker.run() ) adding exec alongside inside which runs each step via exec instead and doesn't override the entrypoint would be in line with other use.

          Jesse Glick added a comment -

          where there is no capability to use exec on a running container

          image.withRun {c ->
            sh "docker exec ${c.id} whatever"
          }
          

          No current plans to offer dedicated features beyond that. Best to have the script be explicit about what it is running.

          Jesse Glick added a comment - where there is no capability to use exec on a running container image.withRun {c -> sh "docker exec ${c.id} whatever" } No current plans to offer dedicated features beyond that. Best to have the script be explicit about what it is running.

          James Hogarth added a comment -

          I've just added a PR for Container.exec() ... I'd really like you to reconsider that as it's very convenient for a few different things (eg ansible testing with a webapp being deployed)

          James Hogarth added a comment - I've just added a PR for Container.exec() ... I'd really like you to reconsider that as it's very convenient for a few different things (eg ansible testing with a webapp being deployed)

            jglick Jesse Glick
            ps Patrick Scharrenberg
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: