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
Ability to run backend separately #257
Comments
@tiangolo I appreciate what you did for us all but please, mention somewhere that default values you've put int /backend/app/alembic/env.py def get_url():
user = os.getenv("POSTGRES_USER", "postgres")
password = os.getenv("POSTGRES_PASSWORD", "")
server = os.getenv("POSTGRES_SERVER", "db")
db = os.getenv("POSTGRES_DB", "app")
return f"postgresql://{user}:{password}@{server}/{db}" |
Do you mean run the DB locally and FastAPI backend locally in a terminal? for env.py include your .env file and then use python-dotenv: import os from alembic import context |
No, I meant to startup backend project locally via docker compose |
that's my yml file # Use postgres/example user/password credentials
version: '3.1'
services:
backend:
image: backend
ports:
- 10088:10088
db:
image: postgres
restart: always
environment:
POSTGRES_SERVER: server
POSTGRES_USER: user
POSTGRES_PASSWORD: pwd
POSTGRES_DB: db
ports:
- 5432:5432
adminer:
image: adminer
restart: always
ports:
- 8080:8080 and that what I'm passing to settings kwargs = {
'SERVER_NAME': '',
'SERVER_HOST': 'http://127.0.0.1:10088',
'PROJECT_NAME': 'CookieBack',
'SENTRY_DSN': '',
...
'POSTGRES_SERVER': '127.0.0.1:5432',
'POSTGRES_USER': 'user',
'POSTGRES_PASSWORD': 'pwd',
'POSTGRES_DB': 'db',
'SQLALCHEMY_DATABASE_URI': 'postgresql://user:pwd@127.0.0.1:5432/db',
'FIRST_SUPERUSER': 'example@mymail.ru',
'FIRST_SUPERUSER_PASSWORD': 'example'}
settings = Settings(**kwargs) by
Still I'm getting this:
How I've could fix that? |
It seems something wrong with my yml setting, because when I'm trying to access postgre container this what I get:
|
If you are running the DB in docker along with the API as you yaml file indicates, you need to refer to the DB by the docker name, not 127.0.0.1. You're passing it the localhost IP and the message shows nothing it talking on that IP & port. Try changing |
No, thats not what helped, but what really helped is to get postgre container IP by running:
Taking that IP and then putting it to SQLALCHEMY_DATABASE_URI and to def get_url():
user = os.getenv("POSTGRES_USER", "example")
password = os.getenv("POSTGRES_PASSWORD", "example")
server = os.getenv("POSTGRES_SERVER", '172.18.0.3:5432')
db = os.getenv("POSTGRES_DB", "example")
return f"postgresql://{user}:{password}@{server}/{db}" UPD |
and when your IP changes? This is why you refer to the service name. |
Yes, I've got this, just needed to launch that at least once |
I'll fork and put that mention to readme and then close this issue. |
Thanks for the help here @wedwardbeck! 🍰 Thanks for coming back to close this issue @orihomie ☕
|
For now its up to 2 days while I'm struggling with postgres docker container and it would've been great if there was any guidelines/ ready compose file to launch them locally and debug that locally.
The text was updated successfully, but these errors were encountered: