Reputation: 629
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.
Upvotes: 0
Views: 800
Reputation: 528
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
Upvotes: 0