What is best practice to access the host's services within a docker container?
I'd like to access PostgreSQL
running on the host within my application which runs in a docker container.
The easiest approach I've found is to use docker container run --net="host"
which, based on this answer, behaves as follows:
Such a container will share the network stack with the docker host and from the container point of view, localhost (or 127.0.0.1) will refer to the docker host.
Be aware that any port opened in your docker container would be opened on the docker host. And this without requiring the -p or -P docker run option.
Which does not seem to be best practice since the containers should be isolated from the host.
Other approaches I've found are awk
ing the hosts IP. May this be the way to go?