1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Unable to get postgressql working right with docker, operation error. the server...

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    For some reason i'm having difficulties trying to get postgressql connected. I've read somewhere that when using postgresql from docker. The localhost changes to the service name. Which in that case looking at my yml file at the postgres definition

    db:
    image: postgres:latest
    container_name: postgres_container
    environment:
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: postgres
    POSTGRES_DB: voting
    networks:
    - app
    volumes:
    - postgres_data:/var/lib/postgresql/data
    ports:
    - "5432:5432"
    - "5433:5433"
    healthcheck:
    test: [ "CMD", "pg_isready", "-U", "postgres" ]
    interval: 10s
    timeout: 5s
    retries: 5


    So upon looking at this definition, the localhost should be db as stated by the yml file

    engine = create_tables_for_voting.create_tables("postgresql+psycopg2://postgres:postgres123@db:5433/voting")
    Session = sessionmaker(bind=engine)
    session = Session()


    This didn't work either as indicated by

    There was an error when connection to db: (psycopg2.OperationalError) could not translate host name "db" to address: No such host is known.

    So i figured why not try use localhost, so upon doing that There was an error when connection to db: (psycopg2.OperationalError) connection to server at "localhost" :):1), port 5433 failed: server closed the connection unexpectedly This probably means the server terminated abnormally

    My final idea through again reading others problem. There was one individual who had an issue that port 5432 kept being used by another instance. Hence why the extra port definitions

    I've been at this for hours, if anyone can guide me through it

    Continue reading...

Compartilhe esta Página