Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-70132

Jenkinsfile docker agent leaves anonymous volumes behind

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • docker-workflow-plugin
    • None
    • docker-worflow-plugin 528.v7c193a_0b_e67c

      For example, the following Jenkinsfile:

      pipeline {
        agent {
          docker {
            image 'docker:dind'
          }
        }
      }
      

      Will create the container based on `docker:dind`, which has a `VOLUME` declared in its Dockerfile, which causes docker to create a volume automatically when running the image (such volumes are called anonymous volumes).

      However, due to the way how Jenkins deletes the container after finishing the build, it will leave the anonymous volume dangling on the agent.

      Over time, this can cause issues as these volumes can consume a high amount of disk space and there's no current Jenkins mechanism to delete them other than "manually".

      For reference, when you run an image with `docker run --rm`, docker will not only delete the container itself but also its anonymous volumes after it exits.

      However, if I add "args `--rm`" to the agent declaration, the build will fail at the end when Jenkins tries to delete the docker agent, and fails the build. If wanted, I can paste the stack trace for the failure here.

      This can be fixed easily by adding the `--volumes` flag to the `docker rm <container>` command which the plugin calls to delete the docker agent after finishing the build (or stage).

            felipecassiors Felipe Santos
            felipecassiors Felipe Santos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: