0

My spring boot app is connecting to postgres and I want to set /etc/hosts like in add-postgres-port-hosts but my container refusing to run when I try to run it using docker run -d -p 8080:8080 springio/flyaway-postgres it fails to run in the background because it tries to find localhost inside the container -

Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections

So how can I run docker exec [container] nc -v -z localhost 5432 in a container that I cannot run in detach mode?

Thank you.

Itsik Mauyhas
  • 3,824
  • 14
  • 69
  • 114
  • Where is the database actually running? Changing `localhost` to point to somewhere other than 127.0.0.1 doesn't seem like a good idea; there must be a better way to tell the migration tool where your database actually is. – David Maze Apr 25 '21 at 10:26
  • You can `docker run any-image some-other-command`; for debugging purposes, frequently `docker run --rm -it any-image sh`; but this won't help you reproducibly run migrations. – David Maze Apr 25 '21 at 10:27
  • The DB runs locally and im able to connect via pg-admin. – Itsik Mauyhas Apr 25 '21 at 11:06
  • What does "locally" mean? (On the same LAN? Inside a multi-process container? Outside a container, but on the same host? In a container, but in a different Docker network?) – David Maze Apr 25 '21 at 11:08
  • Outside of my container on the same host, running he server using postgres pg-admin console and the container is separately running using docker run. – Itsik Mauyhas Apr 25 '21 at 11:21
  • [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) describes the configuration you need here. (On non-Linux, configure your application to use the special host name `host.docker.internal`.) You should not need to adjust `/etc/hosts` anywhere. – David Maze Apr 25 '21 at 11:47

0 Answers0