Flashing ESPHome with Docker

less than 1 minute read

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:

  1. docker run --rm -it is the usual. Remove image when done, use tty
  2. --device /dev/ttyUSB0: Mount ttyUSB0 (your esp device) to the docker container
  3. -v .:/app:ro make the local directory available as readonly to the container as /app
  4. image name
  5. run /app/device.yaml flash said file, which we mounted
  6. --device /dev/ttyUSB0 flash to this device

Keep this running until you see the device log reporting successfully connecting to wifi