I’ve created a droplet with docker pre-installed I’ve pulled the official Postgres image and used the following command to run it
docker run --name postgres -e POSTGRES_PASSWORD=****** -e POSTGRES_USER=**** -d postgres
This image auto exposes the default Postgres port 5432 I can see the container running using: docker ps but cannot connect to it I’m using jetbrains datagrip sql client to connect. I’ve filled the ip host, user/password I’ve set on the Postgres container. My droplet inclues my ssh keys and I could verify that I’m able to connect to my droplet but not to my container. I assume I should use such a tcp client to connect to my droplet ip on 5432 port and I’m suppose to be able to connect to it, right? Did I miss anything? I’ve also tried setting up a network driver using:
docker network create --driver bridge postgres-network
and after stoping and removing the container to recreate it like so:
docker run --name db-postgres --network postgres-network -e POSTGRES_USER=**** POSTGRES_PASSWORD=****** -d postgres
It didn’t work either… Can you please assist me? Thank you Ajar
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey friend!
For that first part, run this instead:
docker run -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=****** -e POSTGRES_USER=**** -d postgres
The container may expose the port, but this will bind it to a port outside of the container for accessibility.
Jarland
This is an old post but since it has no answer i’ll leave one here.
The problem you have is that the port 5432 in which your postgres DB is running is an internal port inside the container, the only thing you’re missing is to map the internal port of your container (5432) to a port inside your localhost so you can connect to it.
Solution: Just add a “-p {any-localhost-port}:5432” to your command and you’ll be good to go.
Example:
Hope this is helpful for someone in the future. Enjoy your coding journey!