Closed ArnyminerZ closed 1 year ago
I've tried removing the custom ports configuration and used the network_mode
option as recommended by the installation guide:
services:
esphome:
container_name: esphome
image: esphome/esphome
user: 0:0
environment:
- HOME="/"
network_mode: host
# ports:
# - "192.168.1.22:6052:6052"
# - "192.168.1.22:6123:6123"
volumes:
- /opt/esphome/config:/config:rw
- /etc/localtime:/etc/localtime:ro
devices:
- /dev/ttyUSB0:/dev/ttyUSB0
restart: always
privileged: true
command: config/ dashboard
But it doesn't fix the issue.
Manually configuring the container's DNS to my router's gateway with:
dns:
- 192.168.1.1
- 8.8.8.8
- 4.4.4.4
Still doesn't make it out. Removing the extra DNS addresses with only
dns:
- 192.168.1.1
throws:
ping: test.local: Temporary failure in name resolution
.local
is resolved with mdns which is a broadcast protocol. You need host networking on your docker container. This isn't an esphome issue.
Confirming same issue.
I have tried host, bridged, custom br0 - with or without privileged mode - with the same result: Unable to resolve .local.
My mdns is handled by my UDM and it resolves correctly on all other devices (even when moving my esp between wifi).
I can ping the ip and the hostname of the esp, but not hostname.local.
All tests are run from within the esphome docker.
Any news here?
So I was having the same issue and this is what worked for me.
Install avahi-daemon in the docker container
apt-get update && apt-get install -y avahi-daemon
Share the host avahi-socket with the container.
` volumes:
However, I don't think this solution would work if your Docker host is not running Linux.
For now, I'm having good luck with adding avahi-daemon to the ESPHome Docker image. This way, it doesn't depend on avahi-daemon running on the host.
avahi-entrypoint.sh:
#!/bin/bash
set -e
avahi-daemon --daemonize --no-drop-root
exec "$@"
Dockerfile:
FROM esphome/esphome:latest
# Hat tip: https://gnanesh.me/avahi-docker-non-root.html
RUN set -ex \
&& apt-get update && apt-get install -y --no-install-recommends avahi-daemon libnss-mdns \
# allow hostnames with more labels to be resolved. so that we can
# resolve node1.mycluster.local.
# (https://github.com/lathiat/nss-mdns#etcmdnsallow)
&& echo '*' > /etc/mdns.allow \
# Configure NSSwitch to use the mdns4 plugin so mdns.allow is respected
&& sed -i "s/hosts:.*/hosts: files mdns4 dns/g" /etc/nsswitch.conf \
&& printf "[server]\nenable-dbus=no\n" >> /etc/avahi/avahi-daemon.conf \
&& chmod 777 /etc/avahi/avahi-daemon.conf \
&& mkdir -p /var/run/avahi-daemon \
&& chown avahi:avahi /var/run/avahi-daemon \
&& chmod 777 /var/run/avahi-daemon
COPY avahi-entrypoint.sh /avahi-entrypoint.sh
ENTRYPOINT ["bash", "/avahi-entrypoint.sh"]
CMD ["/entrypoint.sh", "dashboard", "/config"]
Make sure to run with --network host
!
Could you help us, the simple people, with a guide how to resolve this issue?
FYI, I created a repo which builds ESPhome images with @johnp789 's Dockerfile and pushed to dockerhub based on release tags. For now the release process is manual and I haven't added gchr. https://github.com/esphome/issues/issues/3517#issuecomment-1369256899
Confirming the issue. If ESPhome relies on mDNS, the docker image should come with Avahi so this works out of the box without need for additional entrypoint files and messing with overriding the base image.
Note that I'm also using /etc/avahi/avahi-daemon.conf
:
[server]
enable-dbus=no
[publish]
disable-publishing=yes
This is, in my understanding, to disable reliance on dbus (which requires root permisions - I've created another user in the image so it doesn't use root) and disables mDNS publishing, so the container doesn't try to announce itself as host, just resolves .local
names of other devices.
Here's my Dockerfile:
FROM ghcr.io/esphome/esphome:stable
# Install Avahi for mDNS (resolving .local names)
RUN apt-get update && apt-get install avahi-utils -y
# Remove apt cache
RUN rm -rf /var/lib/apt/lists/*
# Avahi config to not publish and not use dbus.
# See: https://gnanesh.me/avahi-docker-non-root.html
COPY avahi-daemon.conf /etc/avahi/avahi-daemon.conf
# Own the resources by avahi group and set the permissions to allow
# the group to modify them.
RUN chown avahi:avahi /etc/avahi/avahi-daemon.conf \
&& chmod 775 /etc/avahi/avahi-daemon.conf \
&& mkdir -p /var/run/avahi-daemon \
&& chown avahi:avahi /var/run/avahi-daemon \
&& chmod 775 /var/run/avahi-daemon
COPY avahi-entrypoint.sh /avahi-entrypoint.sh
RUN chmod +x /avahi-entrypoint.sh
ENTRYPOINT [ "/avahi-entrypoint.sh" ]
CMD [ "dashboard", "/config" ]
# Create user: don't assign password, create home as it's used by ESPhome to build
RUN adduser --disabled-password --shell /bin/sh user
# Add user to avahi group so it can start the daemon
RUN usermod -a -G avahi user
# Make ESPhome root files readable by the non-root user
RUN chmod 755 -R /piolibs /esphome /platformio.ini \
/platformio_install_deps.py /requirements.txt /requirements_optional.txt
avahi-entrypoint.sh:
is basically the same as one from johnp789
if the problem is to be able to flash a device by OTA with esphome, you can add domain: ""
to the wifi
section in the .yaml
file.
domain default is .local
, and setting it to empty will allow you to reach your device from a docker container.
It's still not working for me with https://github.com/esphome/esphome/pull/5733 And https://github.com/esphome/issues/issues/3517#issuecomment-1369256899 is fixing it for me.
@Thom-x that sounds like it's a problem with your docker host then.
How can we check that ?
On host ping xxx.local
works fine.
The esphome container is using. network_mode: host
also.
Maybe I misunderstood what the workaround was doing. But esphome uses the zeroconf library directly, so running avahi shouldn't make any difference and might even interfere. See if you can do some network sniffing to find out if the packets are getting in and out.
For now, I'm having good luck with adding avahi-daemon to the ESPHome Docker image. This way, it doesn't depend on avahi-daemon running on the host.
avahi-entrypoint.sh:
#!/bin/bash set -e avahi-daemon --daemonize --no-drop-root exec "$@"
Dockerfile:
FROM esphome/esphome:latest # Hat tip: https://gnanesh.me/avahi-docker-non-root.html RUN set -ex \ && apt-get update && apt-get install -y --no-install-recommends avahi-daemon libnss-mdns \ # allow hostnames with more labels to be resolved. so that we can # resolve node1.mycluster.local. # (https://github.com/lathiat/nss-mdns#etcmdnsallow) && echo '*' > /etc/mdns.allow \ # Configure NSSwitch to use the mdns4 plugin so mdns.allow is respected && sed -i "s/hosts:.*/hosts: files mdns4 dns/g" /etc/nsswitch.conf \ && printf "[server]\nenable-dbus=no\n" >> /etc/avahi/avahi-daemon.conf \ && chmod 777 /etc/avahi/avahi-daemon.conf \ && mkdir -p /var/run/avahi-daemon \ && chown avahi:avahi /var/run/avahi-daemon \ && chmod 777 /var/run/avahi-daemon COPY avahi-entrypoint.sh /avahi-entrypoint.sh ENTRYPOINT ["bash", "/avahi-entrypoint.sh"] CMD ["/entrypoint.sh", "dashboard", "/config"]
Make sure to run with
--network host
!
This should be in the documentation.
The problem
My current ESPHome installation on a Raspberry Pi 4 doesn't manage to find the devices on the network.
Trying to access the device's logs on ESPHome Dashboard clearly shows there's an issue finding the device:
Concerned about a misconfiguration of the docker container, which is ran over docker-compose, hereby my
docker-compose.yml
:I've accessed by container's bash terminal with:
And trying to ping my device's hostname has issues with the DNS:
However, pinging the device's IP address (found with Fing on my Android mobile phone):
Which version of ESPHome has the issue?
2022.8.0
What type of installation are you using?
Docker
Which version of Home Assistant has the issue?
No response
What platform are you using?
ESP32
Board
esp32doit-devkit-v1
Component causing the issue
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response