bmuschko / gradle-docker-plugin

Gradle plugin for managing Docker images and containers.
https://bmuschko.github.io/gradle-docker-plugin/current/user-guide/
Apache License 2.0
1.23k stars 361 forks source link

RegistryCredentials not recognized #1191

Closed steffsommer closed 1 year ago

steffsommer commented 1 year ago

I want to push a docker image to a privately hosted Nexus repository using solely the Docker Remote API, because it is not a Java project. I tried configuring the registry credentials + url in the global docker object as well as inside the DockerPushImage task, but my docker push task always attempts to push to the default registry https://index.docker.io/v1/. I think I followed the docs correctly, this is my configuration:

plugins {
    id("com.bmuschko.docker-remote-api") version "9.3.2"
}

// attempted global configuration
docker {
    registryCredentials {
        url = "https://nexus.my-company.com:9004"
        username = nexusUsername
        password = nexusPassword
    }
}

tasks.register<DockerPushImage>("push-docker-image") {
    // attempted task-specific configuration
    registryCredentials {
        url = "https://nexus.my-company.com:9004"
        username = nexusUsername
        password = nexusPassword
    }

    images = listOf("my-image:development")
    dependsOn(buildDockerImage)
}

Expected Behavior

I expected the image to be pushed to https://nexus.my-company.com:9004

Current Behavior

The plugin attempts to push the image to https://index.docker.io/v1/

Context

Steps to Reproduce (for bugs)

Your Environment

OS: Windows 10 Gradle --version: 8.2.1 gradle-docker-plugin-version: Reproducible in 9.3.2 and 9.1.0

steffsommer commented 1 year ago

It turned out that my configuration was wrong. I assumed that the Registry URL would be prepended to the Image name, but that is not the case. So I just hat to update my image name to include the URL of the repository.

So I changed

tasks.register<DockerBuildImage>("build-docker-image") {
    inputDir = file("dist")
    dependsOn(createDockerFile, assembleWebProd)
    images.add("cardiary-web-test:main")
}

to this:

tasks.register<DockerBuildImage>("build-docker-image") {
    inputDir = file("dist")
    dependsOn(createDockerFile, assembleWebProd)
    images.add("nexus.my-company.com:9004/cardiary-web-test:main")
}

I will leave the issue up. Potentially it provide a benefit to extend the push-examples in the documentation to include a build image task, so that users can observe the correct naming convention.

Thank you for providing this plugin!

bmuschko commented 1 year ago

Yes, it's standard convention in Docker to refer to the container image by repository (if you are not pulling from Docker Hub). I am going to close the issue. We do have an example for Harbor in the functional tests but not in the documentation I think.