I’m new to the Streamlit, and also Postgres. I have searched for answer on how to connect and get the data from Postgres while both are in docker containers, but not successfully.
I have successfully connected them on local machine wihout docker, but when they are deployed on the same machine on docker, not working.
Here is the docker-compose file:
version: '1.0' services: postgres: image: postgres environment: POSTGRES_USER: admin POSTGRES_PASSWORD: admin POSTGRES_DB: myDataBase volumes: - postgres-data:/var/lib/postgresql/data ports: - "5432:5432" pgadmin: image: dpage/pgadmin4 restart: always environment: PGADMIN_DEFAULT_EMAIL: email@example.com PGADMIN_DEFAULT_PASSWORD: admin ports: - "5050:80" volumes: postgres-data:
Here is my secrects.toml:
[connections.postgresql] dialect = "postgresql" host = "postgres" port = "5432" database = "myDataBase" username = "admin" password = "admin"
Code in the app is:
# Initialize connection. conn = st.experimental_connection("postgresql", type="sql") # Perform query. df = conn.query('SELECT * FROM myTable;')
OperationalError: (psycopg2.OperationalError) could not translate host name "postgres" to address: Name or service not known (Background on this error at: https://sqlalche.me/e/20/e3q8)
Does anyone know what should be configured differently, because those settings are not working?