I'm not very well-versed in FastAPI, but in Django this problem is solved by adding "docker" (or an alias) to ALLOWED_HOSTS. It seems that in FastAPI you can try to achieve this with Starlette’s TrustedHostMiddleware.