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

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
  1. Named cache directory so we can reuse cache but don’t have to make the main one read-write
  2. --no-logs makes the process quit when the flashing’s done
  3. --group-add keep-groups passes my group membership, which we need because of rootless containers