skip to Main Content

I’m trying to run Postgresql inside Docker, and connect to it via Prisma. I’ve looked at multiple issues and I can’t see anything wrong with what I’m trying to do.

I can’t seem to ping my postgresql instance either, or connect to adminer.

Most common issue people had was with using localhost instead of the docker image name.

I’ve also tried disabling firewalld, but that made no difference so I do not think it’s my firewall blocking the port either.

Thanks!

.env

DB_NAME=spot
DB_HOST=postgres
DB_USERNAME=spotuser
DB_PASSWORD=spotpass
DB_PORT=5432

DATABASE_URL=`postgresql://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?schema=public`

docker-compose.yml

version: '3.1'

services:

  postgres:
    image: postgres
    restart: always
    volumes:
      - ./db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=${DB_USERNAME}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=${DB_NAME}
    ports:
      - 5432:5432

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
❯ docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED         STATUS         PORTS                                       NAMES
e66b70a9ac69   adminer    "entrypoint.sh docke…"   6 minutes ago   Up 2 seconds   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   spot-spot-adminer-1
dd629496a246   postgres   "docker-entrypoint.s…"   6 minutes ago   Up 2 seconds   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp   spot-spot-postgres-1

2

Answers


  1. Chosen as BEST ANSWER

    The problem was me! I usually have a VPN running so I didn't think about it. As soon as I disabled it, everything worked as expected.

    I did however have to use localhost instead of postgresql as my DB_HOST. (I had tried this initially but no luck, that's when I came across a few SO answers that said you need to use container name rather than localhost).


  2. https://docs.docker.com/compose/compose-file/#expose

    Try adding expose to your docker-compose.yml

    version: '3.1'
    
    services:
    
      postgres:
        image: postgres
        restart: always
        volumes:
          - ./db-data:/var/lib/postgresql/data
        environment:
          - POSTGRES_USER=${DB_USERNAME}
          - POSTGRES_PASSWORD=${DB_PASSWORD}
          - POSTGRES_DB=${DB_NAME}
        ports:
          - 5432:5432
        expose:
          - 5432
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search