Back story below, but here's the question: I've discovered that if I have postgresql running on my docker host, I can connect to it in a container via a domain socket mounted as a file:
docker run -v /var/run/postgresql/:/var/run/postgresql
This feels like a major hack, so I'm curious if this is truly horrible in a production environment. Thoughts?
The backstory
The backstory is that I have postgresql running on the docker host because I don't trust docker to run postgresql directly.
So I need to connect to that postgresql instance from a docker container running on the same server. I tried:
Using
--add-host
But this was also a hack because it required that docker run be put inside a script to figure out the right IP of the host machine. Something like:
docker run --add-host=postgres-host:$(ip route show | awk {print $2})
I didn't like having to do that.
I tried using
--net=host
, but...that's not what we want. We want an overlay network.I tried setting this from within the container by looking up the IP address of the host there, but I didn't feel great running a script just for this purpose.
So...I thought: "What about using the domain socket?"