0

Using https://github.com/docker-java/docker-java and looking for a way to add the --with-registry-auth option from https://docs.docker.com/v17.12/engine/reference/commandline/service_create/#options

val createCmd = dockerClient.createServiceCmd(
                ServiceSpec()
                        .withName("name")

                        .withTaskTemplate(TaskSpec()
                                .withContainerSpec(ContainerSpec()
                                        .withEnv(envs)
                                        .withImage("image")
                                        .withMounts(mounts)
                                )
                                .withNetworks(networks)
                                .withPlacement(ServicePlacement()
                                        .withConstraints(constraints))
                        )
        )

To clarify this more:

I am looking for docker-java way to do this command (this does work!):

docker service create --with-registry-auth --constraint 'node.labels.mynodeid==7' myprivateregistry.foo:5000/imagename:latest

Removing the --with-registry-auth like this

docker service create --constraint 'node.labels.mynodeid==7' myprivateregistry.foo:5000/imagename:latest

will bringt up this error: No such image: myprivateregistry.foo:5000/imagename:latest because the credentials, which are valid btw, are not passed to the node.

7
  • Please mention what errors are you getting with this code. Commented Jun 21, 2019 at 15:47
  • I don't get any error. I just don't know how to use the docker-java API to add the mentioned flag. Did search doc and source code but did not find anything. Commented Jun 21, 2019 at 15:49
  • Is it fine if the registry auth is provided in your dockerClient object itself? Commented Jun 21, 2019 at 15:52
  • Building DockerClient object with .withRegistryUsername(), .withRegistryPassword() did not change anything. Commented Jun 21, 2019 at 15:56
  • What was the poblem with these two options, or you just got no output. Commented Jun 21, 2019 at 15:58

2 Answers 2

0

As of docker-java 3.2.0-rc5 you can now specify authConfig to pull images from a private registry

        AuthConfig authConfig = new AuthConfig()
                .withUsername("testuser")
                .withPassword("testpassword")
                .withEmail("[email protected]")
                .withRegistryAddress("your.registry.address.here");

        dockerClient.createServiceCmd(new ServiceSpec()
                .withName(SERVICE_NAME)
                .withTaskTemplate(new TaskSpec()
                        .withContainerSpec(new ContainerSpec()
                                .withImage(DEFAULT_IMAGE))))
                .withAuthConfig(authConfig)
                .exec();
Sign up to request clarification or add additional context in comments.

Comments

0

Specify registry auth details in dockerClient object itself in your code.

Check this out.

If it didn't worked. First verify whether the registry auth details you have are the correct one and manually try to pull docker image using docker cli.

Put registry config in .docker/config.json file and try to pull docker images. And then backtrace the issues.

1 Comment

Thanks, docker cli works, see question. I think either docker-java does not provide a way to pass the option/flag or I cannot find how.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.