JenkinsFile Docker Pipeline Plugin - Question

I have jenkinsfile used in docker pipeline plugin:

pipeline {
  agent {
    docker { image 'node:16-alpine' }
  stages {
    stage('Test') {
      steps {
        sh 'node --version'

This when running creates logs:

+ node --version
[Pipeline] }
$ docker stop --time=1 be3671a65afadef2723b91e52e99df53402e7fe6eceb001b3efe39c108031eb8
$ docker rm -f be3671a65afadef2723b91e52e99df53402e7fe6eceb001b3efe39c108031eb8
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS

I don’t need steps: docker stop, docker rm, i don’t heve them in jenkinsfile, i want my image stay in docker active, how to achive that?

A docker agent starts up when you start working, and shuts down when you stop working.

If you want to run things in the background, it doesn’t sound like an agent.

You can just run docker run -d as an sh statement
or use withRun even withrun will shut down the image when the job is done.

your best bet to have something outlive jenkins is to run docker manually

1 Like

@Marcin you could also build a specific permanent agent starting from inbound-agent or ssh-agent and then add a second FROM directive to inherit from the alpine node image.