Source:
public void testInspectService() throws Exception { requireDockerApiVersionAtLeast("1.24", "swarm support"); final String[] commandLine = {"ping", "-c4", "localhost"}; final String hostname = "tshost-{{.Task.Slot}}"; final TaskSpec taskSpec = TaskSpec .builder() .containerSpec(ContainerSpec.builder().image("alpine") .hostname(hostname) .command(commandLine).build()) .logDriver(Driver.builder().name("json-file").addOption("max-file", "3") .addOption("max-size", "10M").build()) .resources(ResourceRequirements.builder() .limits(com.spotify.docker.client.messages.swarm.Resources.builder() .memoryBytes(10 * 1024 * 1024L).build()) .build()) .restartPolicy(RestartPolicy.builder().condition("on-failure") .delay(10000000L).maxAttempts(10).build()) .build(); final EndpointSpec endpointSpec = EndpointSpec.builder() .addPort(PortConfig.builder() .name("web") .protocol("tcp") .publishedPort(8080) .targetPort(80) .build()) .build(); final ServiceMode serviceMode = ServiceMode.withReplicas(4); final String serviceName = randomName(); final ServiceSpec spec = ServiceSpec.builder() .name(serviceName) .taskTemplate(taskSpec) .mode(serviceMode) .endpointSpec(endpointSpec) .build(); final ServiceCreateResponse response = sut.createService(spec); final Service service = sut.inspectService(response.id()); assertThat(service.spec().name(), is(serviceName)); final Matcher<String> imageMatcher = dockerApiVersionLessThan("1.25") ? is("alpine") : startsWith("alpine:latest@sha256:"); assertThat(service.spec().taskTemplate().containerSpec().image(), imageMatcher); assertThat(service.spec().taskTemplate().containerSpec().hostname(), is(hostname)); assertThat(service.spec().taskTemplate().containerSpec().command(), equalTo(Arrays.asList(commandLine))); }

Target:
public void testInspectService() throws Exception { requireDockerApiVersionAtLeast("1.24", "swarm support"); final String[] commandLine = {"ping", "-c4", "localhost"}; final String hostname = "tshost-{{.Task.Slot}}"; final TaskSpec taskSpec = TaskSpec .builder() .containerSpec(ContainerSpec.builder().image("alpine") .hostname(hostname) .command(commandLine).build()) .logDriver(Driver.builder().name("json-file").addOption("max-file", "3") .addOption("max-size", "10M").build()) .resources(ResourceRequirements.builder() .limits(com.spotify.docker.client.messages.swarm.Resources.builder() .memoryBytes(10 * 1024 * 1024L).build()) .build()) .restartPolicy(RestartPolicy.builder().condition("on-failure") .delay(10000000L).maxAttempts(10).build()) .build(); final EndpointSpec endpointSpec = EndpointSpec.builder() .addPort(PortConfig.builder() .name("web") .protocol("tcp") .publishedPort(8080) .targetPort(80) .build()) .build(); final ServiceMode serviceMode = ServiceMode.withReplicas(4); final String serviceName = randomName(); final ServiceSpec spec = ServiceSpec.builder() .name(serviceName) .taskTemplate(taskSpec) .mode(serviceMode) .endpointSpec(endpointSpec) .build(); final ServiceCreateResponse response = sut.createService(spec); final Service service = sut.inspectService(response.id()); assertThat(service.spec().name(), is(serviceName)); final Matcher<String> imageMatcher = dockerApiVersionLessThan("1.25") ? is("alpine") : startsWith("alpine:latest@sha256:"); assertThat(service.spec().taskTemplate().containerSpec().image(), imageMatcher); if (dockerApiVersionAtLeast("1.26")) { assertThat(service.spec().taskTemplate().containerSpec().hostname(), is(hostname)); } assertThat(service.spec().taskTemplate().containerSpec().command(), equalTo(Arrays.asList(commandLine))); }