Khaled Developer
Khaled Developer

Reputation: 69

can't access Postgres db on Mac when I set port: 5432:5432 but it works fine when I set to 5001:5432

I was setting up docker compose

version: "3.7"
services:
  postgres:
    container_name: mydevdb
    image: postgres:13
    restart: always
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
    volumes:
      - postgres:/var/lib/postgresql/data
    ports:
      - "5432:5432"
volumes:
  postgres:

my env file

POSTGRES_USER=username
POSTGRES_PASSWORD=password
POSTGRES_DB=dev


DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}?schema=public

and when I run Prisma Migrate dev it logs:

Error: P1010

User `username` was denied access on the database `dev.public`

but when I changed ports in docker-compose.yml to "5001:5432" and updated my DATABASE_URL port from 5432 to 5001 it works fine .. I just don't know why that happens in my Mac however my ubuntu machines works well with 5432:5432 port

Upvotes: -1

Views: 177

Answers (1)

Stefan Frye
Stefan Frye

Reputation: 2047

You probably have another instance of postgres running on your mac.

You can run

sudo lsof -PiTCP -sTCP:LISTEN | grep 5432

to check.

Upvotes: 1

Related Questions