1

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
Naphat Amundsen
  • 1,519
  • 1
  • 6
  • 17
  • `none of them work` <= [This does not accurately describe your problem](http://idownvotedbecau.se/itsnotworking/). Do you get a connection refused error ? a tcp close/reset ? a "bad address" or whatever DNS error ? an http redirect to your online banking site ? ... Please edit your question to be as precise as possible. – Zeitounator Feb 12 '22 at 12:37
  • @Zeitounator My apologies, I have updated the question now – Naphat Amundsen Feb 12 '22 at 12:54
  • Did you check you don't have a firewall rule in or a specific configuration in your quarkus server that would allow connections only from localhost (i.e. the host running it) ? – Zeitounator Feb 12 '22 at 14:10
  • 1
    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. Does it make any sense? – Felipe Windmoller Feb 12 '22 at 19:12
  • 1
    @FelipeWindmoller Thank you so much! That was the problem. I guess `host.docker.internal` resolves to an IPv4 address, while the java/quarkus application uses IPv6 or something? I guess I have to read up on such. However, I found out I could do `export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"` to make Java use IPv4 in general, which also solves the issue. I got it from here: https://superuser.com/questions/453298/how-to-force-java-to-use-ipv4-instead-ipv6. If you submit your comment as an answer I can check it as correct :) – Naphat Amundsen Feb 13 '22 at 20:11

1 Answers1

1

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.

Felipe Windmoller
  • 1,528
  • 1
  • 12
  • 24