netplan / docker0 / bind on

netplan / docker0 / bind on

  • Written by
    Walter Doekes
  • Published on

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 "", port 5432
LOG:  could not bind IPv4 address "": Cannot assign requested address
WARNING:  could not create listen socket for ""
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 net.ipv4.ip_nonlocal_bind sysctl setting.

So, if you want to expose, say, your postgresql to a docker instance, you could try to set:
listen_addresses = ','
postgresql will refuse to start unless that 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 /etc/netplan/60-docker.yaml:

  version: 2
  renderer: networkd
        forward-delay: 0ms
        stp: false

postgresql will depend on the network being up, so now it should start on boot again without failing.

Back to overview Newer post: removing auditd / disabling logging Older post: ansible / ipv6 addresses / without link local