0

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)

Beefox
  • 3
  • 2

1 Answers1

0

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...

Ryan.Bartsch
  • 3,698
  • 1
  • 26
  • 52
  • I'm trying to access it through some cs library, I don't remember which as I was doing work on a fork of a program. however I'll give the webserver test another shot and report back – Beefox May 13 '20 at 16:07
  • I have confirmed that the IP is correct using `docker-machine ip default` (default being the name of the machine), and navigating to http://192.168.99.100:8080 once nginx is runnning through docker results in it working apparently! I will retry with the program I was running previously, it may be an issue with that. Either way this did solve the problem of it not connecting, (that problem being me not realising it was not the problem) so thank you! – Beefox May 13 '20 at 16:19
  • For those wondering what was the real issue: I was running my program from the wrong directory so the config file wasn't being checked – Beefox May 13 '20 at 16:35