Failed to connect to socket /tmp/dbus-xxx: Connection refused in docker container after restart host

I’m having trouble connecting to the correct abstract unix socket inside a docker container after the host is restarted.

At container creation, I set the container’s DBUS_SESSION_BUS_ADDRESS to the current value of the host’s DBUS_SESSION_BUS_ADDRESS. Everything works as expected. After the host is restarted, its DBUS_SESSION_BUS_ADDRESS changed but the container still tried to connects to the old socket. To be more specific:

  1. host’s current DBUS_SESSION_BUS_ADDRESS is /tmp/dbus-ABC
  2. start container X and set its DBUS_SESSION_BUS_ADDRESS to /tmp/dbus-ABC (same as host)
  3. restart host
  4. host’s new DBUS_SESSION_BUS_ADDRESS is /tmp/dbus-XYZ
  5. restart container X
  6. get "Failed to connect to socket /tmp/dbus-ABC: Connection refused" inside container because the host’s new DBUS_SESSION_BUS_ADDRESS is /tmp/dbus-XYZ

I know can fix this by update the value of container’s DBUS_SESSION_BUS_ADDRESS every time after I restart the host. But is there a way to automate this?

Have you considered mounting -v /tmp:/tmp, and then modifying the entrypoint script of your image to detect the correct folder, and then export the variable before the main process is started?

As the entrypoint script is executed every time the container starts, it would be the perfect place to fix it within the container itself.

1 Like

Thank you for the suggestion!