If you want to bind your host-service to a the docker IP, exposing it to docker instances, means that that IP needs to exist first. If it doesn't, your log might look like this:
LOG: listening on IPv4 address "127.0.0.1", port 5432 LOG: could not bind IPv4 address "172.17.0.1": Cannot assign requested address WARNING: could not create listen socket for "172.17.0.1" LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
As you probaby know, you cannot bind to an IP that is not configured
on an interface anywhere — barring the
So, if you want to expose, say, your postgresql to a docker
instance, you could try to set:
listen_addresses = '127.0.0.1,172.17.0.1'
postgresql will refuse to start unless that
172.17.0.1 IP exists on
a local interface.
You could reorder your dependencies to have postgresql depend on docker, but that makes no sense from a logical perspective. A better fix is to make sure that the docker IP exists.
Add this in
network: version: 2 renderer: networkd bridges: docker0: addresses: - 172.17.0.1/16 parameters: forward-delay: 0ms stp: false
postgresql will depend on the network being up, so now it should start on boot again without failing.