Recorder connection refused errors after Docker restart

I’m pretty new to Home Assistant, I have a Docker install which I spun up with Docker Compose on an HP Small Form Factor machine. It has been working flawlessly until yesterday when I was making some changes to the config related to a reverse proxy. As a result of these recorder errors, I removed the changes I made and now am trying to track down this issue.

As far as symptoms I’m seeing: The GUI does not come up on Home Assistant, but the container is running and my automations still work, despite the error. I have confirmed the database (Postgresql) is up - and I’m able to log into it with the root user, and the homeassitant user.

My sanitized config below. Appreciate any thoughts you all have.

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

# From the HACS docs
my:

# Text to speech
tts:
  - platform: google_translate

recorder:
  db_url: postgresql://homeassistant:password@localhost:5432/homeassistant

# Prometheus b/c all the metrics
prometheus:
  namespace: ha
  
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# Main config
homeassistant:
  name: Home
  latitude: 12.34
  longitude: 12.34
  elevation: 1234
  unit_system: imperial
  currency: USD
  country: US
  time_zone: "America/New_York"

And a snippet from the errors.

psycopg2.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
	Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (::1), port 5432 failed: Address not available
	Is the server running on that host and accepting TCP/IP connections?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 704, in _setup_recorder
    self._setup_connection()
  File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 1173, in _setup_connection
    Base.metadata.create_all(self.engine)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 4930, in create_all
    bind._run_ddl_visitor(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/future/engine.py", line 341, in _run_ddl_visitor
    with self.begin() as conn:
  File "/usr/local/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/future/engine.py", line 379, in begin
    with self.connect() as conn:
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/future/engine.py", line 406, in connect
    return super(Engine, self).connect()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3315, in connect
    return self._connection_cls(self, close_with_result=close_with_result)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 96, in __init__
    else engine.raw_connection()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3394, in raw_connection
    return self._wrap_pool_connect(self.pool.connect, _connection)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3364, in _wrap_pool_connect
    Connection._handle_dbapi_exception_noconnection(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2198, in _handle_dbapi_exception_noconnection
    util.raise_(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3361, in _wrap_pool_connect
    return fn()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 325, in connect
    return _ConnectionFairy._checkout(self)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 888, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 491, in checkout
    rec = pool._do_get()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 145, in _do_get
    with util.safe_reraise():
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 143, in _do_get
    return self._create_connection()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 271, in _create_connection
    return _ConnectionRecord(self)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 386, in __init__
    self.__connect()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 684, in __connect
    with util.safe_reraise():
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 680, in __connect
    self.dbapi_connection = connection = pool._invoke_creator(self)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 578, in connect
    return dialect.connect(*cargs, **cparams)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 598, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/usr/local/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
	Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (::1), port 5432 failed: Address not available
	Is the server running on that host and accepting TCP/IP connections?
(Background on this error at: https://sqlalche.me/e/14/e3q8)
2023-02-27 20:28:37.726 ERROR (MainThread) [homeassistant.setup] Setup failed for recorder: Integration failed to initialize.
2023-02-27 20:28:38.137 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of history. Setup failed for dependencies: recorder
2023-02-27 20:28:38.137 ERROR (MainThread) [homeassistant.setup] Setup failed for history: (DependencyError(...), 'Could not setup dependencies: recorder')
2023-02-27 20:28:38.141 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of logbook. Setup failed for dependencies: recorder
2023-02-27 20:28:38.141 ERROR (MainThread) [homeassistant.setup] Setup failed for logbook: (DependencyError(...), 'Could not setup dependencies: recorder')
2023-02-27 20:28:38.549 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of energy. Setup failed for dependencies: history, recorder
2023-02-27 20:28:38.549 ERROR (MainThread) [homeassistant.setup] Setup failed for energy: (DependencyError(...), 'Could not setup dependencies: history, recorder')
2023-02-27 20:28:39.038 WARNING (MainThread) [androidtv.adb_manager.adb_manager_async] Couldn't connect to 192.168.10.106:5555.  BrokenPipeError: Broken pipe
2023-02-27 20:28:39.040 WARNING (MainThread) [homeassistant.config_entries] Config entry '192.168.10.106' for androidtv integration not ready yet: Could not connect to Android TV / Fire TV device at 192.168.10.106:5555 using Python ADB implementation with adbkey='/config/.storage/androidtv_adbkey'; Retrying in background
2023-02-27 20:28:39.042 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of default_config. Setup failed for dependencies: energy, history, logbook
2023-02-27 20:28:39.043 ERROR (MainThread) [homeassistant.setup] Setup failed for default_config: (DependencyError(...), 'Could not setup dependencies: energy, history, logbook')

Arg! I’ll answer my own question - in hopes that it helps someone.

It seems like the cause of this was not the config, but it was the removal of network_mode: host in the docker compose file. After putting that back, things work again.

Another helpful thread is this one, which actually outlines what I was trying to do with Traefik, which seems like was the cause of this in the first place.