# Troubleshooting

## General

[AI Agents](https://updates2mqtt.rhizomatics.org.uk/help/ai_help/index.md) can give very good help these days, even the free one built into [Google Search](https://updates2mqtt.rhizomatics.org.uk/help/ai_help/#google-example), and the [FAQs](https://updates2mqtt.rhizomatics.org.uk/help/faqs/index.md) cover common questions.

Things that need to work:

- Docker API access to list and inspect containers
- MQTT Publication of results
- Home Assistant discovering the Update entities on MQTT
- Home Assistant generating update notices in UI when there’s a new version
- Command Topic message sent by Home Assistant when Update button clicked
- Docker Compose available from shell to make updates and restart
- Git command available in shell to check for local repo updates and pull

## Updates2MQTT Logs

If running under docker, and following the container naming guidance, then see the logs using:

`docker logs updates2mqtt`

or change to the directory where the `docker-compose.yaml` is installed and do `docker compose logs`

### Changing Log Level

Update the `config.yaml` and change the log level to DEBUG, which will show much more diagnostic information.

conf/config.yaml

```yaml
log:
  level: DEBUG
```

When you have everything working, its best to change the log level back, so your container isn’t generating big logs.

### Going Inside Container

From the `docker-compose.yaml` directory, execute

`docker compose exec -it updates2mqtt bash`

(if you have an old Docker install, you may need to use `docker-compose` instead of `docker compose`)

This will give you shell access inside the container, which is a good way of checking for path issues, permissio issues etc. For example, if you have compose directories in the `/containers` directory, you could `cd /containers` and validate that Updates2MQTT can see the other compose directories, `ls` the contents, and run `docker compose` or `git` actions there.

## MQTT

If the host, port, user and password for MQTT are incorrect then usually this will show in the logs, or use a MQTT client to verify that Updates2MQTT is successfully posting to topics ( and that HomeAssistant itself is publishing to the same broker OK).

Updates2MQTT uses the [Eclipse Paho Python Client](https://github.com/eclipse-paho/paho.mqtt.python) for all MQTT interaction, using v2 of the callback API, and supports the older MQTT implementations as well as the newer v5 protocol. The [Issues](https://github.com/eclipse-paho/paho.mqtt.python/issues?q=is%3Aissue) list might give you some clues for your situation.

### Checking MQTT and Update Settings

The CLI can show the MQTT and update settings Updates2MQTT will use, and try a connection to the broker. It reads the environment variables and `conf/config.yaml` the same way the app does, logs every value along with the environment variable it comes from, and only shows whether passwords are set, not their values.

Run it inside the running container, so it sees exactly the same environment and config file:

```bash
docker exec -it updates2mqtt u2m-cli mqtt=check
```

Or from anywhere with uv, with the MQTT environment variables set, and optionally a config file:

```bash
MQTT_HOST=192.168.1.10 MQTT_USER=u2m MQTT_PASS=xxx uvx --from updates2mqtt u2m-cli mqtt=check
uvx --from updates2mqtt u2m-cli mqtt=check config=/path/to/config.yaml
```

It also shows the update settings - `allow_pull`, `allow_restart`, `allow_build`, `remove_old_image`, `max_concurrent_updates` and the Portainer API settings - so you can confirm env vars like `PORTAINER_CA_CERTS` or `U2M_REMOVE_OLD_IMAGE` are being picked up. The Portainer API key is shown only as set or not set.

The check reports missing required values (such as `MQTT_USER`) and certificate files that don’t exist, including the Portainer `ca_certs`. It doesn’t try to connect if the MQTT settings are invalid. It exits with status 0 if the broker connection succeeds and the update settings are valid, and 1 otherwise, so it can also be used in scripts. It uses its own MQTT client id, so is safe to run alongside a live Updates2MQTT without disconnecting it.

### MQTT Clients

Use a desktop MQTT app - [MQTTX](https://mqttx.app) will let you subscribe to `#` and see everything on a broker, while [MQTT Explorer](https://mqtt-explorer.com) automatically shows a tree structure of topics, and can run either as a desktop app, or as [web app running on Docker](https://github.com/Smeagolworms4/MQTT-Explorer).

These tools will let you inspect messages, and also publish your own, so can create your own update message and see if it gets picked up by the Home Assistant app.

Alternatively, use the debug option and logging of Mosquitto broker, or the built-in admin/debug UI of EMQX broker. Or the handy command line `mosquitto_sub` and `mosquitto_pub`, which are also used by the Updates2MQTT health check.

## Home Assistant

### Checklist

(All of these can be checked and changed via the Home Assistant UI.)

- HA is configured with an MQTT integration
- MQTT broker host and port is the same on HA as Updates2MQTT
  - Updates2MQTT has been tested with Mosquitto and EMQX
- Automatic *Discovery* is on
- The discovery prefix matches Updates2MQTT ( they both default to `homeassistant`)

See the examples at [Home Assistant Configuration](https://updates2mqtt.rhizomatics.org.uk/home_assistant/#configuration)

In addition to the base MQTT configuration, Updates2MQTT relies on [MQTT Discovery](https://www.home-assistant.io/integrations/update.mqtt/) and [MQTT Update](https://www.home-assistant.io/integrations/update.mqtt/) integrations. All of these have a single set of [MQTT Issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+label%3A%22integration%3A+mqtt%22).

When configured, each monitored container will have an `update` entity visible in the [Home Assistant Developer Tools](https://www.home-assistant.io/docs/tools/dev-tools/) and [Entities View](https://www.home-assistant.io/docs/configuration/entities_domains/).

#### Home Assistant Mosquitto HassOS App

If using the default *Mosquitto* broker, and *Customization* switched on, check the ACL configuration has `readwrite` access give to the Updates2MQTT user for its topics. The [HomeAssistant add-in config](https://github.com/home-assistant/addons/blob/master/mosquitto/DOCS.md) puts this in the `/share/mosquitto` directory.

Oddly, the Paho MQTT client used by Updates2MQTT is known to [report success even when broker rejects message because of ACL restrictions](https://github.com/eclipse-paho/paho.mqtt.python/issues/895).

#### Alternative MQTT Discovery

There’s also an alternative to MQTT Discovery in HA, using plain yaml, the [MQTT Update Integration](https://www.home-assistant.io/integrations/update.mqtt/#configuration). The [BBQKees Boiler Gateway](https://bbqkees-electronics.nl/wiki/home-automations/home-assistant-configuration.html) has some detailed steps and examples for MQTT Discovery too.

#### No Update Button

If there’s an update showing, but no *Update* button present, then there’s a few reasons, which can be checked directly from the config and log:

- Config has the `allow_pull`,`allow_restart` and `allow_build` all overridden to `False`
- A new version reference can’t be found
- The compose working directory can’t be found
- This is sourced from the `com.docker.compose.project.working_dir` label, which can be seen in `docker inspect`
- Check `compose_path_found` in the MQTT attributes, if `false` the directory needs mapping as a volume, at exactly the same path
- Portainer stacks have a working directory of `/data/compose/<stack id>`, inside Portainer’s own volume, so need Portainer API access configured, see [Portainer](https://updates2mqtt.rhizomatics.org.uk/configuration/portainer/index.md)
- This only stops restart, not pull, so if `allow_pull` is on, the Update button will still show
- The git repo path can’t be found for a local build

The current state of this can be seen in MQTT, the config message will have two extra values as below:

```json
  "command_topic": "updates2mqtt/dockernuc/docker",
  "payload_install": "docker|homarr|install"
```

#### Home Assistant Logs

Use the [System Log](https://www.home-assistant.io/integrations/system_log/) to check for MQTT errors, or for positive confirmation that Update entities have been discovered. The *raw* log will show more, and allow you to scroll back for hours.

The [Logger Integration](https://www.home-assistant.io/integrations/logger/#viewing-logs) lets you tweak the levels of specific integrations. This is less useful for Updates2MQTT, since all the work is happening outside of Home Assistant, however it can be useful for general MQTT issues, and the examples in the Home Assistant documentation shows how to tune the MQTT integration.

## Docker

More detailed information on the Docker API and compatibility with Docker engine versions can be found at Docker’s own [Docker Engine API](https://docs.docker.com/reference/api/engine/) reference.

`updates2mqtt` is designed to run on the same host as the containers, so only needs local Docker daemon access. All it needs for that is the volume mapping as below:

Example Docker Compose Snippet

```yaml
volumes:
  - /var/run/docker.sock:/var/run/docker.sock
```

Where `docker-compose` projects are being automatically updated and restarted, one problem can be that earlier versions used a `docker-compose` command and newer ones use `docker compose`. There is a `v1` and `v2` option in the [configuration](https://updates2mqtt.rhizomatics.org.uk/configuration/index.md) to support this, defaulting to `v2`.

If the `updates2mqtt` container is not running as root, then ensure that the user is a member of the local `docker` group. (If it is running as root, then consider moving to a defined user, see [Running as Non-Root](https://updates2mqtt.rhizomatics.org.uk/configuration/security/#running-as-non-root)).

### Docker Help

Best place to start is the `docker-py` [Issues](https://github.com/docker/docker-py/issues?q=is%3Aissue) on GitHub, since this is the primary component inside Updates2MQTT.

A simple way of testing if there’s a `docker-py` issue is to load the client directly from python. This example uses `uv` to avoid changing local Python environment, use `pip` or other preferred tool to install if you want instead.

```bash
uv run --with docker python3
>>> import docker
>>> docker.__version__
>>> client = docker.from_env()
>>> client.info()['Containers']
```

This should output the version of the `docker` package, and the total count of local containers if the connection is good. Updates2MQTT uses at least v7.1.0 of `docker` for Python API.

## Registry API

Updates2MQTT uses the Docker developed `docker-py` library for local management, and originally for discovering updates. Now by default it uses the more modern [OCI v2 Distribution API](https://github.com/opencontainers/distribution-spec/blob/main/spec.md) that `docker.io` and other registries have supported for years.

The `api` option in Docker`registry` config can override this, set to `docker_client`,`oci_v2` or `disabled`.

The OCI APIs require more network calls, typically one to retrieve a token, one for the image index, which points to the platform specific manifest, and finally the config document. On the other hand, well-developer images also provide annotations on these documents, which allow for direct links to release notes and source code, descriptions, semantic versions and more.

Registries usually have an unauthenticated token system for authorization. Private registries, or a higher Docker Hub rate limit, need the `docker login` credentials to be visible to Updates2MQTT, see [Private Registries](https://updates2mqtt.rhizomatics.org.uk/configuration/remote_api_usage/#private-registries). A token can also be given per container using the `updates2mqtt.registry_token` container label or `UPD2MQTT_REGISTRY_TOKEN` environment variable.

If the benefits of the extra calls ( release summaries, direct release note URLs, human friendly version numbers ), then the additional fetches can be skipped by using `OCI_V2_MINIMAL` as the `api` value in the registry configuration section.

Tip

Images built on GitHub often use the `docker-metadata` action to create the annotations, which is documented at [metadata-action](https://github.com/docker/metadata-action)

## Too Many Requests

The Docker Registry API has a limit on how many authenticated requests, and a lower limit for unauthenticated requests, can be made per hour.

Access to the API will back off when this is hit, and discovery will wait until a configurable period passed, which can be configured using `default_api_backoff` in the `docker` configuration section, with a value in seconds.

The throttling is determined per registry, so if Docker is throttling it won’t affect `gchr.io`, private registries or others. They will also throttle if needed, but again the throttle will only affect that specific registry, and other scans will continue.

The order of containers scanned is shuffled every time, so if there is a lot of throttling it won’t be the same ones every time.

## Docker CLI

There is a very bare bones command line debug tool, that will look up an image in either v1 or v2 APIs and dump everything to console at `DEBUG` log level, while also retrieving tokens to authorize API access and adapting to Docker Hub, GitHub, GitLab or Codeberg registries.

Use the *container* hash, or a container name if one has been given ( easy to find out either of these with `docker ps`)

There’s no need to install Updates2MQTT to use the manifest and blob fetching ability.

```bash
uvx --from updates2mqtt u2m-cli manifest=ghcr.io/blakeblackshear/frigate:stable
```

The following examples will all work from any Python context, and don’t need a local Docker or any Docker access.

```bash
uvx --from updates2mqtt u2m-cli manifest=ghcr.io/blakeblackshear/frigate:stable
uvx --from updates2mqtt u2m-cli blob=ghcr.io/blakeblackshear/frigate@sha256:ef8d56a7d50b545af176e950ce328aec7f0b7bc5baebdca189fe661d97924980
uvx --from updates2mqtt u2m-cli manifest=ghcr.io/blakeblackshear/frigate@sha256:c68fd78fd3237c9ba81b5aa927f17b54f46705990f43b4b5d5596cfbbb626af4
uvx --from updates2mqtt u2m-cli tags=ghcr.io/blakeblackshear/frigate
uvx --from updates2mqtt u2m-cli manifest=mcr.microsoft.com/dotnet/sdk:latest
```

These examples refer to locally running containers, displaying the local info as well as remote registry

```bash
uvx --from updates2mqtt u2m-cli container=frigate
uvx --from updates2mqtt u2m-cli container=f4f02e182f5e api=docker_client
uvx --from updates2mqtt u2m-cli container=frigate api=docker_client log_level=DEBUG
```

To keep it installed as a command, add it as a uv tool, which puts `u2m-cli` on the path:

```bash
uv tool install updates2mqtt
u2m-cli container=frigate api=docker_client
```

If the package is installed in a local Python environment, it can also be run directly:

```bash
python -m updates2mqtt.cli container=frigate api=docker_client
```

Get a dump to CSV rather than MQTT of local Docker containers

```bash
python -m updates2mqtt.cli dump=csv
```
