0

I have a postgres database running in a docker container. I'm able to connect to the postgres server using pgadmin. However, when I try to connect to the database using IntelliJ, I get the error:

"cannot connect to "postgres". The connection attempt failed"

Here is the connection information using pgadmin:

hostname: postgres

username: postgres

password: postgres

port: 5432

database: SpringDevDB

When I try the same information using Intellij, I get the error above.

rds80
  • 631
  • 1
  • 10
  • 23
  • This might be useful https://stackoverflow.com/a/30116292/2704032 – Vishrant Jan 11 '23 at 03:18
  • I'm guessing PGAdmin is running in a container but IntelliJ isn't? The connection details will be different in a container vs. not; outside a container you probably need `hostname: localhost`, and for a `port:`, the first port number from a `docker run -p` or Compose `ports:` option. – David Maze Jan 11 '23 at 12:09

1 Answers1

0

Did the pgadmin is hosted in Docker?

If yes, then you can try if the standalone pgadmin could connect to it or not.

This might be caused by default for security reasons in the Docker container that no network ports will expose to the client out of the docker instance itself. So try to add a -p flag to expose it to see if it works:

docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres -p 5432:5432