Skip to main content
edited tags
Link
Ilja Everilä
  • 53.4k
  • 9
  • 137
  • 141
Source Link
Omri Shneor
  • 1k
  • 3
  • 21
  • 36

PostgreSQL with docker compose and sqlalchemy

Hey im trying to create a postgresql db container, im running it using the command:

docker-compose up

on the following compose file:

version: '3.1'
services:

  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_USERNAME: admin
      POSTGRES_PASSWORD: admin
      POSTGRES_DB: default_db
    ports:
      - 54320:5432

However when I try to connect to it using the follwoing python code:

import sqlalchemy
engine = sqlalchemy.create_engine('postgres://admin:admin@localhost:54320/default_db')
engine.connect()

I get the following error:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL:  password authentication failed for user "admin"

Anyone knows why this happens?