How to pull docker image from private registry to the open shift cluster under image streams using using fabric8 java client

  docker, fabric8, java-8, openshift

I am trying to pull a docker image from my private repository using fabric8 docker client for java.

The secret and image stream gets created on the open shift cluster but the image count shown as 0 as the image does not get pulled from the private repository .

This is my code . Please suggest to pull the image from private repo(abc/hello-world) …

public boolean createImageStream(String token, ImageStreamRequest imageStreamRequest) throws BaseExceptionBean{
        LOGGER.info("----- creatImageStream started STARTED --");
        try {
          final String namespace;
         final User user = new User(imageStreamRequest.getUserName());
         user.setUserName(imageStreamRequest.getUserName());
          String secretName = null;
          //imageStreamRequest.setUserName(imageStreamRequest.getUserName());
          //imageStreamRequest.setRegistryUrl(imageStreamRequest.getRegistryUrl());
          OpenShiftClient userClient = createOpenShiftClient(user);
          namespace = imageStreamRequest.getNameSpace(imageStreamRequest.getUserName()) ;
          LOGGER.info("Using configured namespace: {}", namespace);
          
         // secretName = resolveSecret(userClient, namespace, imageStreamRequest);
          
          final boolean secretSuccess = createOrUpdateSecret(imageStreamRequest, userClient);
            if (!secretSuccess) {
                LOGGER.info("Error Creating secret for User:{}", user.getUserName());
            }
        
          TagReference pol = new TagReference();
          pol.setReferencePolicy(new TagReferencePolicy("Local"));
        
          pol.setName("latest");
          
          final ImageStream imageStream = userClient.imageStreams().inNamespace(namespace).createOrReplace(new ImageStreamBuilder()
                .withNewMetadata()
                .withName("hello-world-private1")
                .withNamespace(namespace)
                .endMetadata()
                .withNewSpec().withTags(pol).withDockerImageRepository("abc/hello-world")
                .endSpec()
                .build());

          LOGGER.info("Created image stream: {}", imageStream.getMetadata().getName());
          
        } catch (final Exception ex){
            LOGGER.error("Exception occurred while creating ImageStream:" +ex.getMessage());
            throw new SystemException(ErrorMessageConstant.errorPrefix + ErrorMessageConstant.CODE_4009_MSG,
                    ErrorMessageConstant.CODE_4009_MSG, new Date(), ex.getMessage(), SystemException.SYSTEM.OPENSHIFT);
        }

       return true;
    }

Source: Docker Questions

LEAVE A COMMENT