You may find this plugin more useful.
I had a PR merged a few months ago that optimizes the API for this plugin so that it can be used nicely with the Gradle Kotlin DSL:
https://github.com/bmuschko/gradle-docker-plugin
Not quite what you were looking for but this may help.