question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't reach database server which run in Docker

See original GitHub issue

I currently try run Postgresql in Docker, and use that database in prisma2 in my docker list, my Postgresql running on localhost:5555 and I connecting it on DBeaver, it was successfully , after i run prisma2 app with Postgresql in docker-compose it does’t work,

my docker-compose.yml like this

version: "3"
services:
  app:
    env_file:
      - .env
    build:
      context: .
      dockerfile: Dockerfile
    links:
      - postgres
    ports:
      - "8100:8100"
  postgres:
    container_name: postgres
    image: postgres:10-alpine
    ports:
      - "5555:5432"
    environment:
      POSTGRES_USER: username
      POSTGRES_PASSWORD: mypassword
      POSTGRES_DB: prod

in my .env DB_URI = postgres://username:s@localhost:5555/prod for my schema.prisma

and after I run my docker-compose I got error like this :

Error: P1001: Can't reach database server at `localhost`:`5555`

Please make sure your database server is running at `localhost`:`5555`.

thought my Postgresql already running on that localhost:5555 is there any way to resolve this ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:27 (7 by maintainers)

github_iconTop GitHub Comments

14reactions
umlx5hcommented, Feb 14, 2021

I think this issue should be closed because lacking docker basic network knowledge is the cause of the problem in the first place. If you want to ask a question about Docker networking, you can do it on stackoverflow or to learn.

12reactions
pantharshit00commented, Jan 21, 2020

Localhost inside docker is bound to the container, not the machine. So you can’t access your postgres container via localhost on inside you application docker container. So please use postgres(the container name) instead of localhost as a host in order to connect to your database instance.

If you still want to access your machines loopback interface inside docker for some reason, you can use host.docker.internal(It doesn’t work on linux though). But I would highly recommend you to use your container name as the database host.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: P1001: Can't reach database server at `localhost`:`5432`
I'm having a problem when running the npx prisma migrate dev command. Docker desktop tells me that the database is running correctly on...
Read more >
Docker Prisma Error P1001: Can't reach database server at ...
Apparently, when running inside a container, instead of the localhost , it uses the container's name. I changed my docker compose to specify...
Read more >
please make sure your database server is running at ...
To connect to database from the application container, use postgres:5432 (If they are on the same network) or <dockerhost>:5432 . Open side panel....
Read more >
Multi container apps - Docker Documentation
Create the network. $ docker network create todo-app · Start a MySQL container and attach it to the network. · To confirm we...
Read more >
NestJS + Redis + Postgres Local Development With Docker ...
Docker Compose set up for NestJS, Redis and Postgres ... you from getting the error: Error: Can't reach database server at localhost:5432.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found