Flashing ESPHome with Docker
ESPHome’s WebSerial connection didn’t work for me, and the computer running ESPHome was a bit far.
Instead, I decided to run a local copy of ESPHome to flash the firmware over USB, and figured it’s an incantation worth keeping
First, save your target yaml locally, e.g. device.yaml.
Then:
docker run --rm -it --device /dev/ttyUSB0 -v .:/app:ro ghcr.io/esphome/esphome run /app/device.yaml --device /dev/ttyUSB0
Some breakdowns:
docker run --rm -itis the usual. Remove image when done, use tty--device /dev/ttyUSB0: Mount ttyUSB0 (your esp device) to the docker container-v .:/app:romake the local directory available as readonly to the container as/app- image name
run /app/device.yamlflash said file, which we mounted--device /dev/ttyUSB0flash to this device
Keep this running until you see the device log reporting successfully connecting to wifi
Podman update
I moved to podman, and improved the original incantations a bit
podman run --group-add keep-groups --rm -v .:/app:ro -v esphome-cache:/app/.esphome ghcr.io/esphome/esphome run /app/device.yaml --device /dev/ttyUSB0 --no-logs
- Named cache directory so we can reuse cache but don’t have to make the main one read-write
--no-logsmakes the process quit when the flashing’s done--group-add keep-groupspasses my group membership, which we need because of rootless containers