I created a Docker Container as follows:
docker run -e POSTGRES_USER=docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=docker library/postgres
I now want to connect it to Datagrip to query. When I try to setup a connection in Datagrip, it fails.
DataGrip Connection Failed Error
I fetched the host ip from inspect container <container_id>
which came out to be 172.17.0.2
on port 5432
.
Please see image for reference. Config Settings for the container However, the connections still keeps failing when i try connecting to DataGrip.
Does anyone know how to go about it??
The reason DataGrip failed to connect to your container running Postgres is you didn't expose any port of the container, in this case 5432
.
The IP address of the container you fetched, i.e. 172.17.0.2
, is the container's internal IP address within the docker container's network, in your case bridge
, the default network your container connects to if you didn't specify --network={NETWORK}
option of docker run
.
Although there're ways to find the "real" IP address of the container, they're invariably too convoluted to be useful for you purpose. The easiest way for DataGrip to connect to your Postgres container is to publish your port 5432
and map it to the same port (or any other available port) of your host machine, by running:
docker run -e POSTGRES_USER=docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=docker -p 5432:5432 library/postgres
with a -p 5432:5432
option.
After that you should be able to connect to your container from DataGrip by specifying localhost
as host. Please see this screenshot for reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With