Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access a REST API of Springboot on host.docker.internal #8155

Open
jhollmannk opened this issue Jan 29, 2025 · 2 comments
Open

Cannot access a REST API of Springboot on host.docker.internal #8155

jhollmannk opened this issue Jan 29, 2025 · 2 comments
Assignees
Labels
kind/bug Something isn't working
Milestone

Comments

@jhollmannk
Copy link

jhollmannk commented Jan 29, 2025

Actual Behavior

With the Bugfix version 1.17.1 another error came into play that prevents us from using RancherDesktop in our development environment.

The scenario is this: We start a docker compose environment with several applications in it including an nginx. The application in development runs in an IDE on the host and we route all traffic in the nginx.conf via host.docker.internal to the application in the IDE. That worked just fine in 1.16.0.

But now nginx times out while reading the response from the application on host.docker.internal.

Steps to Reproduce

Attached is a zip file containing the smallest springboot application I could think of and a compose file to start an nginx container.

You will need a Java 21 JDK and Apache Maven to run this though.

In the restapp folder start the nginx container with docker compose up -d. This starts the nginx with the provided configuration routing /test to the springboot application via host.docker.internal.

Then start the application with mvn spring-boot:run. That should build and start the springboot application.

In another DOS box you can call curl -v http://localhost:8090/test which accesses the application directly to check that it really works and returns a JSON:

* Host localhost:8090 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8090...
* Connected to localhost (::1) port 8090
> GET /test HTTP/1.1
> Host: localhost:8090
> User-Agent: curl/8.9.1
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 200
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Wed, 29 Jan 2025 07:24:42 GMT
<
{"content":"test"}* Connection #0 to host localhost left intact

Now call curl -v http://localhost:8080/test which accesses the nginx container which routes the call to the application and tries to read the JSON response.

restapp.zip

Result

The call fails with the curl output

* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8080...
* Connected to localhost (::1) port 8080
> GET /test HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.9.1
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 200
< Server: nginx/1.26.2
< Date: Wed, 29 Jan 2025 07:42:05 GMT
< Content-Type: application/json
< Transfer-Encoding: chunked
< Connection: keep-alive
<
* transfer closed with outstanding read data remaining
* closing connection #0
curl: (18) transfer closed with outstanding read data remaining

and the log of nginx

2025/01/29 07:42:10 [error] 30#30: *1 upstream timed out (110: Connection timed out) while reading upstream, client: 192.168.143.2, server: localhost, request: "GET /test HTTP/1.1", upstream: "http://192.168.127.254:8090/test", host: "localhost:8080"
192.168.143.2 - - [29/Jan/2025:07:42:10 +0000] "GET /test HTTP/1.1" 200 0 "-" "curl/8.9.1"

Expected Behavior

The response should be read successfully and returned to curl.

Additional Information

My guess is that there is a problem, when the response does not have a newline at the end of the content?

I even didn't have a problem when I return a String instead of a Java object. There is no new newline at the end here too. But a Content-Length header is set which, I presume, is handled by nginx so that the response is read successfully.

As this worked fine in 1.16.0 I hope you can find the cause of this.

Rancher Desktop Version

1.17.1

Rancher Desktop K8s Version

1.31.4

Which container engine are you using?

moby (docker cli)

What operating system are you using?

Windows

Operating System / Build Version

Windows 10 Enterprise 22H2

What CPU architecture are you using?

x64

Linux only: what package format did you use to install Rancher Desktop?

None

Windows User Only

SecurePoint SSL VPN
Bitdefender

@jhollmannk jhollmannk added the kind/bug Something isn't working label Jan 29, 2025
@dbielik
Copy link
Contributor

dbielik commented Jan 30, 2025

We're seeing exactly the same problem on Windows. Nginx container is not able to forward requests to the host via host.docker.internal neither to Java app nor to JS app. Curl from the nginx container works fine.

@Nino-K
Copy link
Member

Nino-K commented Feb 7, 2025

This issue could potentially be related to: #8208

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants