gradle-docker-plugin: DockerBuildImage fails to pull public repo images if registryUsername registryPassword are present

I have the exact same issue as: #275 which was closed for some reason.

I have docker gradle file that has the following closure.

docker{
    registryCredentials  {
        username = System.env.DOCKER_USERNAME
        password = System.env.DOCKER_PASSWORD
    }
}

task buildOfficialCorrettoDockerImage(type: DockerBuildImage, dependsOn: [buildDockerFolder]) {
    inputDir = new File(project.buildDir, "docker-temp")
    tags = correttoBuildTags
    dockerFile = new File(new File(project.buildDir, "docker-temp"), "DockerfileAL")
}

When running this the following error:

Could not build image: Get https://registry-1.docker.io/v2/library/amazonlinux/manifests/2: unauthorized: incorrect username or password

When I run without the credentials closure, it builds fine, but then obviously I cannot push to the registry because we do not have the credentials.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

@cdancy Yes, that will work now with the proposed DSL.

@bmuschko well I don’t want to change the existing credentials just point at a different registry for this specific task which I believe your PR addresses.

@cdancy I assume you are just asking about the DSL-aspect of it? And the use case is only the one if you wanted to assign different credentials for two different custom tasks? If that’s the case then it’s easy to achieve. I’d suggest opening a new issue.

BTW: You do not need to create a new instance of DockerRegistryCredentials. You can just change the values of the existing property registryCredentials. So this should work:

task dockerBuildImage(type: DockerBuildImage) {
    registryCredentials.with {
         url.set('new url')
         username.set('new username')
    }
}

Will try asap, not at computer for today!