I'm trying to interact with a dockerized PostgreSQL server using SQLAlchemy. Something like:
engine = create_engine('postgresql://user:user_password@localhost:5432/database')
df.to_sql('table', engine)
Which gives me this error:
OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
Which suggests the Docker postgresql (which is running) isn't available at that port. I've tried adding -p 5432:5432
to my docker-compose exec
without success. Any tips?