Docker container not announcing mDNS at 'homeassistant.local'

I wish to access my HA instance via the common hostname “homeassistant.local”.
I am using the official docker image and the container gets its own IP address using docker macvlan networking.

I can see that HA is broadcasting mDNS, but the hostname is “ec4be13571b84b88b6eeeb8051692f79.local” instead of “homeassistant.local”:

Accessing “http://ec4be13571b84b88b6eeeb8051692f79.local:8123” does work.

Docker-compose:

networks:
  macvlan:
    external: true
    name: macvlan

services:
  homeassistant:
    container_name: home-assistant
    image: homeassistant/home-assistant
    volumes:
      - /volume1/docker/ha/data:/config
      - /etc/localtime:/etc/localtime:ro
    environment:
      - PUID=1036
      - PGID=65538
    devices:
      - /dev/ttyUSB1:/dev/ttyUSB1
    restart: always
    hostname: homeassistant
    networks:
      macvlan:
        ipv4_address: 192.168.1.242

Where is this 32 character seemingly random mDNS hostname coming from?

If you goto UI->Settings->System->Network, at the top of the page it says “Hostname”.
What does yours say? Anyway if it doesn’t say homeassistant, perhaps type it in and save it and see what happens.

[Edit] I did find a Thread on this issue. Don’t know if it has actually been fixed or not.

Add a hostname to your compose file.
You should do this with all containers and use hostname, not ip, whenever possible when communicating on docker network

This will be applied to macvlan as well


version: "3.0"
services:
  web:
    image: nginx:latest
    hostname: my-web-server

hey all, I’ve been experiencing this problem too. I run HA in Docker on a Synology NAS and, previously, a FritzBox router. I think it was linked here that someone thought this was related but I’ve binned the FritzBox and I’m still having the same problem.
I’ve done some digging and it looks like it’s intended behaviour - at least if the internal Instance ID isn’t set.
core/homeassistant/components/zeroconf/__init__.py at e64f76bebe1ce804622e40b5097778537ec1228e · home-assistant/core · GitHub - this looks to be the line that calls the instance_id internally which, in my case, is returning a UUID-like string. If you override this line with just ‘homeassistant.local’ it seems to fix the problem but I have limited confidence that it hasn’t broken something else.
The better question would be what is the internal instance ID and how is it derived.