Naphat Amundsen
Naphat Amundsen

Reputation: 1623

Cannot reach quarkus application on host from inside docker container

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

Upvotes: 3

Views: 2922

Answers (2)

MichaelCkr
MichaelCkr

Reputation: 690

I had the same problem and was misled by the answer here, which is only because I have missed one detail in the question. Without this detail, I ran into the exact same issue, but setting IPv4 has not solved the problem (though starting quarkus from an uber-jar fixed the issue).

However, I just want to emphasize, that not setting quarkus.http.host=0.0.0.0 leads to the same problem described in the question. (Perhaps this will help another less thorough reader of the question.)

By default, quarkus is Listening on: http://localhost:8080, which will not be sufficient to call it from a docker container.

So, the quarkus.http.host is necessary here.

See also How to make Quarkus to listen on all network interfaces instead of localhost?.

Upvotes: 1

Felipe Windmoller
Felipe Windmoller

Reputation: 1753

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.

Upvotes: 2

Related Questions