Home > Software design >  Cannot reach quarkus application on host from inside docker container
Cannot reach quarkus application on host from inside docker container

Time:02-14

This is not a duplicate of From inside of a Docker container, how do I connect to the localhost of the machine?. I have already attempted the suggestions in the aforementioned thread, and I know how to fix this problem in general. This problem seems to be specific to quarkus applications. I manage to make everything work except for the quarkus server.

Context

  1. I have obtained a quarkus application template from https://code.quarkus.io/, of which includes a shell file called mvnw, which I can use to start a development server by executing ./mvnw quarkus:dev -Dquarkus.http.host=0.0.0.0 -Dquarkus.http.port=9000 -Ddebug=9001 in the host terminal.
  2. I can now go to http://localhost:9000 in the browser. I can also do curl localhost:9000 and see that I get the HTML/CSS/JS code.

Issue

I cannot reach the quarkus server from within a docker container. I have tried:

  1. Run a base curl container: docker run --rm -it --name curl --entrypoint sh curlimages/curl:latest
  2. From within the container I attempt the following:
    • curl host.docker.internal:9000 -> Connection refused
    • curl localhost:9000 -> Connection refused
    • curl (the machine host name here):9000 -> Operation timed out (this happens for all ports)
    • Run the container with --network=host, and use curl localhost:9000 -> Connection refused
    • Various other suggestions from the post mentioned at the top, but all get connection refused

However, I can connect to the JVM debug port using curl host.docker.internal:9001 (Empty reply from server), and I can also connect to a Python http fileserver (hosted from host) using the host.docker.internal hostname. It seems to be that it is only the quarkus server that I cannot connect to.

What I want: A reliable way to connect to the host's quarkus container from within a docker container

System info

  • OS: Windows 11 21H2 22000.493 , but I do everything within WSL2 (Ubuntu 20.04.3 LTS).
  • CPU: Intel Core i7-10850H

CodePudding user response:

Could you try to disable the IPV6 on your wsl2 and repeat your test?

$ sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
$ sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1

I had similar issues and this solved the problem for me.

  • Related