Gradle Plugin for Docker


I am reading this documentation:

You can create and push your docker image into hub.
My question is:
is there a way, just to make an command in gradle, to open terminal and start the command? Because, saving password of his account from docker.hub is not so nice, for example you work in a group and have to share your project with others?

I would like to have a terminal, where I put the command, and the terminal will ask me for user-name and password…

That would be much nicer, does anybody have an idea/tip about it?
Thanks a lot


You can define the credential variables as following (see the Gradle project properties documentation for more information):

def dockerRegistryCredentials = new DockerRegistryCredentials() = rootProject.hasProperty('email') ? rootProject['email'] : 'default_value'
dockerRegistryCredentials.password = rootProject.hasProperty('password') ? rootProject['password'] : 'default_value'
dockerRegistryCredentials.username = rootProject.hasProperty('username') ? rootProject['username'] : 'default_value'

After that, you will be able to add your credentials to the command line via the -P command line option:
gradlew pushImage -Pemail=value -Pusername=value -Ppassword=value

1 Like

Thanks a lot, I will take a look on it :slight_smile:

Hi Natalia,

I want to ask you for another tip.

task buildImage(type: DockerBuildImage, dependsOn: createDockerfile) {
    inputDir = createDockerfile.destFile.parentFile
    tags = ['sample-sales', '{docker-hub-username}/{default-repo-folder-name}:sample-sales']
    registryCredentials = dockerRegistryCredentials

Is there a way to make it like the example you show me above?

gradlew pushImage -Pemail=value -Pusername=value -Ppassword=value

What I want is, to call the pushImage command with the password, username etc. with it, also with the “docker-hub-username”, is there a way to do it? Or does you have a tip for me? Thanks a lot :slight_smile:

EDIT: I saw that the url has the default value:

So I can replace it, like you show me above.
I will try it now

Hi, you can replace the '{docker-hub-username}/{default-repo-folder-name}:sample-sales' with the following

rootProject.hasProperty('docker-hub-username') ? rootProject['docker-hub-username'] : 'default_value' + '/' + rootProject.hasProperty('default-repo-folder-name') ? rootProject['default-repo-folder-name'] : 'default_value' + ':<projectName>'

and it will work similarly