I am building a Flask application in Python. I'm using SQLAlchemy to connect to PostgreSQL.
I used this to successfully connect my SQLALchemy in the flask app to my postgresql.
engine = create_engine('postgresql://postgres:[mypassword]@localhost:5432/employee-manager-db')
However, I run into an error when I try to do docker-compose up. 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:
- 'db:5432'
I don't know why it is not recognizing db as an object.
Edit: I had the same problem as this (Docker: Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?) and tried to fix it, but I am currently facing this error instead. Thank you so much for your help
CodePudding user response:
The ports
option for a service is a list of <host_port>:<container_port>
mappings. Both the <host_port>
and <container_port>
parts need to be integers, which db
is not.
You probably want:
db:
image: postgres:14.5
restart: always
expose:
- '5432'
volumes:
- .dbdata:/var/lib/postgresql
ports:
- '5432:5432'