0

I have Docker installed in my Windows machine and a Spring Boot app with the docker-java library running on Eclipse.

Everything works perfectly fine using this configuration:

 DockerClientConfig dockerClientConfig = DefaultDockerClientConfig.createDefaultConfigBuilder()
    .withDockerHost("tcp://localhost:2375")
    .withDockerTlsVerify(false)
    .build();

DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder()
    .dockerHost(dockerClientConfig.getDockerHost())
    .sslConfig(dockerClientConfig.getSSLConfig())
    .maxConnections(100)
    .build();

DockerClient dockerClient = DockerClientImpl.getInstance(dockerClientConfig, httpClient);

Now I put my Spring Boot app within a container:

DockerFile

FROM openjdk:11
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

But now I get this error

org.apache.hc.client5.http.HttpHostConnectException: Connect to http://localhost:2375 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

Any idea why it stops working when I put my code inside the container? Somehow it cannot access the docker host.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

Containers are designed to be isolated. What you have to do is to establish a network between your two containers.

Josh
  • 69
  • 3