Can't reach database server which run in Docker
See original GitHub issueI 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:
- Created 4 years ago
- Comments:27 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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 usepostgres
(the container name) instead oflocalhost
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.