I am trying to use docker and run my image with this Java Library: com.github.dockerjava
Here is the code :
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.CreateContainerCmd;
import com.github.dockerjava.api.command.PullImageResultCallback;
import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.api.model.Container;
import com.github.dockerjava.api.model.ContainerNetwork;
import com.github.dockerjava.api.model.Image;
import com.github.dockerjava.core.DockerClientBuilder;
public static void main(String[] args) {
String containerName = "mycontainer_name";
String dockerImage = "myimage";
// Get the Docker client
System.out.println("Get Docker client");
DockerClient dockerClient = DockerClientBuilder.getInstance().build();
// Check if the container is already running
if (dockerContainerExists(containerName, dockerClient)) {
System.out.println("Container already exists");
dockerStop(containerName, dockerClient);
DockerRm(containerName, dockerClient);
}
CreateContainerCmd createContainer = dockerClient
.createContainerCmd(dockerImage).withName(containerName);
createContainer.withTty(true);
createContainer.exec();
dockerClient.killContainerCmd(containerName).exec();
dockerClient.removeContainerCmd(containerName).exec();
// runDataGenerator(new Pcap(), args);
}
Here is my pom.xml dependency :
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java</artifactId>
<version>3.3.0</version>
</dependency>
But I get this error :
Exception in thread "main" java.lang.IllegalArgumentException: Unsupported protocol scheme: npipe:////./pipe/docker_engine
at com.github.dockerjava.jaxrs.JerseyDockerHttpClient.<init>(JerseyDockerHttpClient.java:225)
at com.github.dockerjava.jaxrs.JerseyDockerHttpClient.<init>(JerseyDockerHttpClient.java:49)
at com.github.dockerjava.jaxrs.JerseyDockerHttpClient$Builder.build(JerseyDockerHttpClient.java:124)
at com.github.dockerjava.core.DockerClientBuilder.build(DockerClientBuilder.java:106)
at org.package.main(Pcap.java:1108)
I am on Windows and have Docker Desktop running (by the way it works perfectly on Linux) and I saw the same type of error for other people but I couldn't find any answers. If someone has the answer to this or has faced the same problem I am up for answers...