Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cpfarherFinitestate opened this issue Apr 17, 2024 · 0 comments

Comments

@cpfarherFinitestate
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant