Issue
I am building a Flask application in Python. I'm using SQLAlchemy to connect to PostgreSQL.
In the flask application, I'm using this to connect SQLAlchemy to PostgreSQL
engine = create_engine('postgresql://postgres:[mypassword]@db:5432/employee-manager-db')
And this is my docker-compose.yml
version: '3.8'
services:
backend:
build:
context: .
dockerfile: Dockerfile
ports:
- 8000:8000
volumes:
- .:/app
depends_on:
- db
db:
image: postgres:14.5
restart: always
expose:
- '5432'
volumes:
- .dbdata:/var/lib/postgresql
ports:
- '5432:5432'
environment:
POSTGRES_PASSWORD: [mypassword]
However, I get an error saying "Is the server running on host "db" (172.21.0.2) and accepting TCP/IP connections on port 5432?"
These are my docker containers:
Inside the employee-manager_db_1, it says "PostgreSQL init process complete; ready for start up". Inside the employee-manager_backend_1, it says "psycopg2.OperationalError: could not connect to server: Connection refused. Is the server running on host "db" (172.21.0.2) and accepting TCP/IP connections on port 5432?"
Thank you so much for help.
Solution
I solved it adding pgadmin service.
pgadmin:
image: 'dpage/pgadmin4'
restart: always
....
Answered By - NendoRiki
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.