✅ Getting Error 400: Invalid Hostname when trying to access application in Docker container
Hello, I have a .net 7 application running inside a Docker container. The .NET application has an endpoint to generate PDFs of a Razor site.
It is using pupeteer to generate the pdf, so it needs to access its own page:
I'm trying to access the page using localhost:
http://localhost:80/api/...
That works without any flaws when running the application outside of the docker container during development, but once its deployed it nolonger works.
I'm receiving 400: Invalid Hostname
errors when the headless chromium tries to access localhost.
I also tried curling from within the container to localhost and get the same response:
My Program.cs looks like this:
Inside my Startup I never set any specific host.
I do set the AllowedHosts
through my AppSettings tho:
That results in the application listening on Now listening on: http://[::]:80
which is what I expect.
Just for completeness here is my dockerfile:
2 Replies
Are your headless chrome & api in 2 different containers?
Hello no they are not in different containers.
I was able to fix it by setting the external hostname inside the hosts file of the container and pointing this to 127.0.0.1