Docker Agents

Running Build Steps Inside a Docker Agent

Projects need different Node.js 2,131 or Java versions, and permanent agents accumulate them. The Docker 514 Pipeline plugin (docker-workflow 653.v2f2c08eff0ec, installed with the CLI) runs steps inside a container from any image, so the agent needs only Git 1,932 , Java and the Docker CLI:

dk-inside: npm ci inside node:24-slim on the SSH agentGroovy
node('docker') {
  git url: 'https://github.com/binarybehemoth/booknest-jenkins.git', branch: 'main'
  docker.image('node:24-slim').inside('--cpus 1 --memory 1g') {
    sh 'node --version && id -u && npm ci --no-audit --no-fund'
  }
  sh 'ls -ld node_modules && ls node_modules | wc -l'
}
Output
$ docker run -t -d -u 1000:1000 --cpus 1 --memory 1g -w /var/lib/l2-agent-ssh/workspace/dk-insi
...
added 82 packages in 3s
...
drwxr-xr-x 81 jenkins jenkins 4096 Sep 25 16:16 node_modules

inside starts the container with cat as its command, runs each sh through docker exec, and removes the container afterward. Steps run as the agent's user (-u 1000:1000) in the shared workspace, so node_modules survives, owned by jenkins. Because the agent itself is a container driving the host's daemon, the plugin used --volumes-from the agent's container instead of a -v path the host lacks. Mounting the workspace at the same path on host and agent keeps a build's own docker run -v "$WORKSPACE":/src working.