Thanks to visit codestin.com
Credit goes to github.com

Skip to content

com.github.dockerjava.api.exception.DockerClientException: Could not build image #2318

Closed
@cpfarherFinitestate

Description

@cpfarherFinitestate

Hello I'm tring to build and run an image from a docker file using java. For that I have this dependencies in maven:

docker-java 3.3.6
docker-java-api 3.3.6
docker-java-core 3.3.6

I'm using this code:

 URL resourceUrl =
                        UploadBinaryScanRecorder.class.getClassLoader().getResource("com/fs/docker/Dockerfile");

        // Docker client configuration
        DefaultDockerClientConfig config =
                DefaultDockerClientConfig.createDefaultConfigBuilder().build();
        DockerClient dockerClient = DockerClientBuilder.getInstance(config).build();

        BuildImageCmd buildImageCmd = dockerClient.buildImageCmd();

        // Step 2: Set the Dockerfile
        buildImageCmd.withDockerfile(new File(resourceUrl.getFile()));

        // Step 3: Execute the build and get the result callback
        BuildImageResultCallback resultCallback = new BuildImageResultCallback() {
            @Override
            public void onNext(com.github.dockerjava.api.model.BuildResponseItem item) {
                // Handle build response
                System.out.println(item.getStream());
            }
        };

        buildImageCmd.exec(resultCallback);

        // Step 4: Await the image ID
        String imageId = resultCallback.awaitImageId(); // line 215

The exception was trigger in the line 215: String imageId = resultCallback.awaitImageId();

I confirmed that the image was build successfully:

Step 1/2 : FROM python:3.9-alpine
 ---> 8f4429cefc37

Step 2/2 : ENTRYPOINT [ "python3","--version"]
 ---> Using cache
 ---> a6b29bfb7257
null
Successfully built a6b29bfb7257

But I got this error and I don't understand why:

ERROR: Build step failed with exception
com.github.dockerjava.api.exception.DockerClientException: Could not build image
	at com.github.dockerjava.core.command.BuildImageResultCallback.getImageId(BuildImageResultCallback.java:77)
	at com.github.dockerjava.core.command.BuildImageResultCallback.awaitImageId(BuildImageResultCallback.java:52)
	at com.finitestate.uploadbinaryscan.XXXX.perform(UploadBinaryScanRecorder.java:215)
	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:47)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:818)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:767)
	at hudson.model.Build$BuildExecution.post2(Build.java:179)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:711)
	at hudson.model.Run.execute(Run.java:1925)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
	at hudson.model.ResourceController.execute(ResourceController.java:101)
	at hudson.model.Executor.run(Executor.java:442)

I need to get the imageId in order to run it later.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions