I have a multi-Docker application with a Streamlit frontend and a FastAPI backend deployed on Heroku: https://morning-everglades-39854.herokuapp.com/
The code is on GitHub: https://github.com/BioGeek/streamlit-fastapi-langchain (add an OPENAPI_API_KEY to a .env file if you want to reproduce).
It has:
- a frontend folder with a Dockerfile and streamlit_app.py file
- a backend folder with a Dockerfile and an api.py file
- a docker-compose.yml file
- a heroku.yml file
locally, I can do:
docker compose build
docker compose up
and go to http://172.19.0.3:8501, ask a math question and get an answer:
But after deploying the app on Heroku with
heroku create
heroku stack:set container
git push heroku main
heroku open
and trying the same math question there, I get the error:
ConnectionError: HTTPConnectionPool(host='api', port=8080): Max retries exceeded with url: /ask (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9f5e00d040>: Failed to establish a new connection: [Errno -2] Name or service not known'))
Traceback:
File "/usr/local/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
exec(code, module.__dict__)
File "/app/streamlit_app.py", line 34, in <module>
main()
File "/app/streamlit_app.py", line 24, in main
response = requests.request("POST", host, headers=header, data=payload)
File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 520, in send
raise ConnectionError(e, request=request)
How do I fix this?