Can't overwrite dockerfile tag in declarative pipeline

I’m running Jenkins in a docker container, and each agent is it’s own docker container specified by their own Dockerfiles. The problem is that this eats up all my disk space because jenkins tags each docker image with some hash, ie.

docker build -t c83bea504ba5821d16993281b93536740e567b55 -f Dockerfile .

I tried specifying my own tag with additionalBuildArgs but that just appends another tag and two images get created

docker build -t c83bea504ba5821d16993281b93536740e567b55 -t project-test:latest -f Dockerfile .
$ sudo docker image ls
REPOSITORY                                 TAG       IMAGE ID       CREATED         SIZE
c83bea504ba5821d16993281b93536740e567b55   latest    b46746417e26   3 minutes ago   568MB
project-test                               latest    b46746417e26   3 minutes ago   568MB

How can I specify my own tag for the docker images? Examples from the docker plugin documentation seem to use a scripted pipeline to customize more aspects of docker images but that makes other things like workspace cleanup more complicated.


pipeline {
    agent {
        dockerfile {
            additionalBuildArgs '-t project-test:latest'
            args '''
    stages {
        stage('Build') {
            steps {
                sh '''#!/bin/bash
                    echo dummy build command
        stage('Test') {
            steps {
                sh 'echo dummy test command'
    post {
        always {
            cleanWs(cleanWhenNotBuilt: false,
                    deleteDirs: true,
                    disableDeferredWipeout: true,
                    notFailBuild: true)

The two images that were created are in fact just one image with two different tags (see the IMAGE ID).

How often do you rebuild your images?
Can’t you build them when it’s needed, and reference them in the pipeline?
Are these private? If so, do you have a private registry?