I am new to docker. I have vm player and running ubuntu LTS image running on it.
I have a docker image of postgres DB running in it.
From my laptop, I have spring boot based application running and I have to specify the ip address of postgres.
How to get ip address of postgres container? Please help.
Did you expose the port of your container? Probably not.
If you expose a port the container behaves like a normal programm on your computer. So your ip is localhost.
If your spring boot application runs on the host and the postgres container publishes the container port 5432 to the contaienr port 5432, then localhost:5432 is correct.
If your spring boot application runs in a different container in the default docker network, you need to link your spring boot container with the postgres container and use the link to address the database. The default docker network has no buildin dns server.
If your spring boot application runs in a different container in the same custom network, you can simply rely on the networks dns and use servicename:5432 to access the database.
.
Hello meyay,
Thanks for your reply.
It is my dev environment. In my laptop, I have IDE and im trying connect to postgres docker deployed on a ubuntu image using VM Player. How to go about it? Please suggest.
Okay, I uderstand that you want to be abe to run the spring boot application within your IDE (Eclipse, IntelliJ or something else…) on the host AND inside the VM. Technicaly both is possible.
On last thing: please share the exact docker run command or docker-compose.yml that you use to start the postgres container.
If intelliJ is inside the vm, you need to use localhost:5432 to access the postgres database.
If intelliJ is running on the host, it pretty much depends if your VM uses the NAT or Host-only network.
If the network uses the Host-only network, you need to use ip of the vm:5432 to connect to postgres.
If the network uses NAT network, you need to start “Virtual Network Editor” as admin, select on the NAT network, click on “NAT Settings…” button, click “add” to add your port forwarding. Then you need to use localhost:5432 (or whatever host port you defined) to connect to postgres.
If you need help with NAT portforwarding, I would suggest to raise a topic in a vmware forum.