Connecting to docker postgres database

When running the command npx prisma db pull
✔ ~/Project_Development/carspectra [main L|● 1✚ 2]
05:25 $ npx prisma db pull
Prisma schema loaded from prisma/schema.prisma
Environment variables loaded from .env
Datasource "db": PostgreSQL database "carspectra", schema "public" at "localhost:5432"

✖ Introspecting based on datasource defined in prisma/schema.prisma

Error: P1000

Authentication failed against database server at `localhost`, the provided database credentials for `admin` are not valid.

Please make sure to provide valid database credentials for the database server at `localhost`.
✔ ~/Project_Development/carspectra [main L|● 1✚ 2]
05:25 $ npx prisma db pull
Prisma schema loaded from prisma/schema.prisma
Environment variables loaded from .env
Datasource "db": PostgreSQL database "carspectra", schema "public" at "localhost:5432"

✖ Introspecting based on datasource defined in prisma/schema.prisma

Error: P1000

Authentication failed against database server at `localhost`, the provided database credentials for `admin` are not valid.

Please make sure to provide valid database credentials for the database server at `localhost`.
And here's my .env file Database URL
DATABASE_URL="postgresql://admin:test@localhost:5432/carspectra?schema=public"
DATABASE_URL="postgresql://admin:test@localhost:5432/carspectra?schema=public"
And ive confirmed the creation of the postgres db within my container logs, and the ability to manually connect to the container:
✘-1 ~/Project_Development/carspectra [main L|● 1✚ 2]
05:26 $ docker exec -it docker_postgres psql -U admin -d carspectra
psql (15.10 (Debian 15.10-1.pgdg120+1))
Type "help" for help.

carspectra=#
✘-1 ~/Project_Development/carspectra [main L|● 1✚ 2]
05:26 $ docker exec -it docker_postgres psql -U admin -d carspectra
psql (15.10 (Debian 15.10-1.pgdg120+1))
Type "help" for help.

carspectra=#
And for reference here's the docker-compose.yml file for building the postgres db:
services:
postgres:
image: postgres:15
container_name: docker_postgres
restart: always
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: test
POSTGRES_DB: carspectra
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data

volumes:
postgres_data:
services:
postgres:
image: postgres:15
container_name: docker_postgres
restart: always
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: test
POSTGRES_DB: carspectra
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data

volumes:
postgres_data:
1 Reply
Nurul
Nurul5w ago
Hello @Freshleys_HoneyBun! 👋 Once your docker container is running, are you able to connect to the database via pgAdmin, or any other GUI tool with this connection string: "postgresql://admin:test@localhost:5432/carspectra?schema=public"?

Did you find this page helpful?