Search code examples
macospostgresqldocker

How do you connect to postgres running in a Docker container on OSx?


I have postgres running in a Docker container on OSx. At first I tried connecting to it locally. I started the container with:

docker run -i -d -h localhost -p 5432:5432 --name some-postgres -t my-postgres:9.6 postgres

After some digging, I found out that you cannot connect to it over localhost on OSx, you need to connect to the ip address that docker is using internally. So I used docker-machine to create a vm at 192.168.99.100:2376. However, I am still unable to connect to postgres over 192.168.99.100:5432. What am I missing? Any help would be greatly appreciated.


Solution

  • If you have Docker for Mac, then it should work on localhost as is: https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds