Docker-java: pullImageCmd with registry config in DefaultDockerClientConfig

Created on 28 Jun 2017  路  5Comments  路  Source: docker-java/docker-java

Hi!

I am trying to pull an image from a private repository.

If I run the pullImageCmd providing an AuthConfig It works successfully :

AuthConfig authConfig = new AuthConfig().withUsername(username).withPassword(password)
.withRegistryAddress("https://xxxx.dkr.ecr.us-west-2.amazonaws.com");

dockerClient.pullImageCmd("xxxx.dkr.ecr.us-west-2.amazonaws.com/xxxx/xxxx")
.withTag("1.1").**withAuthConfig(authConfig)**
.exec(new PullImageResultCallback()).awaitCompletion();

But if I set the registry configuration when creating the DockerClient it doesn麓t work

DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder().withRegistryPassword(password)
.withRegistryUsername(username)
.withRegistryUrl("https://xxxx.dkr.ecr.us-west-2.amazonaws.com")
.withDockerHost(environmentConfig.getDockerAgentAddress()).build();
dockerClient.pullImageCmd("xxxx.dkr.ecr.us-west-2.amazonaws.com/xxxx/xxxx")
.withTag("1.1").
.exec(new PullImageResultCallback()).awaitCompletion();

Why pullImageCmd is not using the DockerClientConfig when AuthConfig is not provided?

Thanks!

resolutiostale

All 5 comments

Why pullImageCmd is not using the DockerClientConfig when AuthConfig is not provided?

Feel free to debug code.

OK, but It supposed to work as I explained? Or I did something wrong?

Problem was related with method getAuthConfig() in DefaultDockerClientConfig

  private AuthConfig getAuthConfig() {
        AuthConfig authConfig = null;
        if (getRegistryUsername() != null && getRegistryPassword() != null && getRegistryEmail() != null
                && getRegistryUrl() != null) {
            authConfig = new AuthConfig()
                    .withUsername(getRegistryUsername())
                    .withPassword(getRegistryPassword())
                    .withEmail(getRegistryEmail())
                    .withRegistryAddress(getRegistryUrl());
        }
        return authConfig;
    }

It is being checked that every registry field is not null. In ECR for example, you have not email. If email is setted to "" when creating DockerClientConfig then works, but I don麓t think that is the clearest way. Maybe, in the function above is not necessary to check that every field is not null

I got error locally and this PR helped https://github.com/docker-java/docker-java/pull/868/commits/e640aff1c72a143d260b73db81fe38df0322703d, i cherry-picked it and found null auth issue, then added fixup and updated test json.

If you have some additional configs you can create test case (or check already existing PRs).

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings