2

I want to run the following command from within a Java Eclipse Project:

docker container run -p 4000:5000 virtuprint:vp

where virtuprint:vp is an image. I installed the docker-java api from here https://github.com/docker-java/docker-java using all its dependencies via maven. I am using MacOS, I guess that's causing my trouble.

I already read the docs and wikis, and just did some test code to see if it's running (and of course it's not.)

DockerClient dockerClient = DockerClientBuilder.getInstance().build();

        List<Container> containers = dockerClient.listContainersCmd().exec();

        for(Container c: containers) {
            System.out.println(c.getId());
        }

So I just want to print the container-ID in short term. Long term I want to run multiple docker containers on demand from within my java application. But if I run the code I get:

java.lang.NoClassDefFoundError: Could not initialize class org.newsclub.net.unix.NativeUnixSocket

I guess it's because he is trying to find unix sockets on places they aren't, but I neither know where they are nor how to tell him where to find them.

ThanhPhanLe
  • 1,315
  • 3
  • 14
  • 25
Flontis
  • 307
  • 1
  • 4
  • 13

2 Answers2

1

Played with the dependencies, downgraded to version 3.0.14 and sticked closely to this guide: https://www.baeldung.com/docker-java-api

don't know why but now it works.

Flontis
  • 307
  • 1
  • 4
  • 13
0

I also faced the same issue, but the issue got resolved when I switched to JAVA 8. There is an issue with JAVA11 and higher versions.

JAVA 11 and Docker-java issue

Ravi Wadje
  • 1,145
  • 1
  • 10
  • 15