При попытке запуска выходит ошибка:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "db" to address: Temporary failure in name resolution
Сервис запуска БД с Postgres в компос-файле:
db:
command: mkdir db
image: postgres:14.6
container_name: postgres-db
#restart: always
environment:
POSTGRES_PASSWORD: "example"
POSTGRES_DB: "db_docker"
POSTGRES_HOST_AUTH_METHOD: trust
expose:
- 5432
volumes:
- ./db:/var/lib/postgresql/data/pgdata
- ./setting/init.sql:/docker-entrypoint-initdb.d/init.sql
Подключение к БД в приложении:
class Connect_DB():
def __init__(self):
self.PASS_DB = 'example'
self.HOST = 'db'
self.USER_DB = 'postgres'
self.DB = 'db_docker'
self.db_connect = f'postgresql://{self.USER_DB}:{self.PASS_DB}@{self.HOST}:5432/{self.DB}'