Search code examples
dockervirtual-machinevirtualboxdocker-toolbox

Cannot access postgres database inside of a docker container run with docker toolbox


I am using docker toolbox to run docker on windows 10 home, and I can't seem to access a postgres database running in a container.

The database is definitely running, as I can see the container by using docker container ls.

The port of the database, 5432, seems to be published, and I can see it by running netstat -atnon the virtual machine. netstat shows

Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 :::5432                 :::*                    LISTEN

From what I understand, I should now be able to access it with the docker machines IP address (192.168.99.100), as well as the port number (5432). However this did not seem to work.

I then tried adding the port to the port forwarding of the vm, both guest and host port as 5432 and leaving the IPs of the host and guest blank. But I still cannot access it.

I have tried the host of the database connection to be localhost and 192.168.99.100, and nothing.

I can reach 192.168.99.100 with ping, and ssh.

I have tried fresh installs, turning it off and on again, and countless other solutions I have seen suggested for similar problems, and nothing seems to work.


This also isn't restricted to just this postreg database, it seems anything hosted in a container in the default machine cannot be accessed from the host machine. I have also tried web servers in containers and no luck (I haven't tried anything else because that's beyond my knowledge)


Solution

  • How are you trying to access the Postgres container? If you're trying to access this using HTTP by entering http://192.168.99.100:5432 into a web browser; it's probably not going to work as presumably there's no webserver listening for HTTP requests on the postgres image you're using.

    Can you try running docker run -p 8080:80 nginx and then accessing http://192.168.99.100:8080 in a web browser. Also make sure the that's the correct IP address by running docker-machine ip <name-of-machine> - just to make sure...