Wiki source code of Home Assistant on Docker
Last modified by Normann P. Nielsen on 2025/12/12 15:13
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | = Docker start first time = |
| 2 | |||
| 3 | |||
| 4 | {{code}} | ||
| 5 | sudo docker run --init --restart on-failure -d --name="home-assistant" -v /home/bnp/homeassistant:/config -v /etc/localtime:/etc/localtime:ro --net=host -v /run/dbus:/run/dbus:ro homeassistant/home-assistant | ||
| 6 | {{/code}} | ||
| 7 | |||
| 8 | = Restart = | ||
| 9 | |||
| 10 | |||
| 11 | {{code}} | ||
| 12 | sudo docker restart "home-assistant" | ||
| 13 | {{/code}} | ||
| 14 | |||
| 15 | = Upgrade = | ||
| 16 | |||
| 17 | |||
| 18 | {{code}} | ||
| 19 | sudo docker stop "home-assistant" | ||
| 20 | tar -cvf homeassistant.tar homeassistant/* | ||
| 21 | sudo docker rm "home-assistant" | ||
| 22 | sudo docker pull homeassistant/home-assistant:latest | ||
| 23 | docker run -d --restart on-failure --name="home-assistant" -v /home/bnp/homeassistant:/config -v /etc/localtime:/etc/localtime:ro -v /run/dbus:/run/dbus:ro --net=host homeassistant/home-assistant | ||
| 24 | {{/code}} | ||
| 25 | |||
| 26 | = Troubleshooting = | ||
| 27 | |||
| 28 | if HA wont start or the container keeps restarting: | ||
| 29 | |||
| 30 | |||
| 31 | {{code}} | ||
| 32 | docker logs --tail 50 --follow --timestamps "home-assistant" | ||
| 33 | {{/code}} | ||
| 34 | |||
| 35 | or run the container in the foreground: | ||
| 36 | |||
| 37 | |||
| 38 | {{code}} | ||
| 39 | docker run -ti "home-assistant" | ||
| 40 | {{/code}} | ||
| 41 | |||
| 42 | = Rollback = | ||
| 43 | |||
| 44 | |||
| 45 | {{code}} | ||
| 46 | sudo docker stop "home-assistant" | ||
| 47 | sudo docker rm "home-assistant" | ||
| 48 | tar -xvf homeassistant.tar | ||
| 49 | sudo docker images | ||
| 50 | {{/code}} | ||
| 51 | |||
| 52 | Remove the newest image (tagged as latest) | ||
| 53 | |||
| 54 | |||
| 55 | {{code}} | ||
| 56 | sudo docker rmi 66b09e12c04f | ||
| 57 | {{/code}} | ||
| 58 | |||
| 59 | List images again | ||
| 60 | |||
| 61 | |||
| 62 | {{code}} | ||
| 63 | sudo docker images | ||
| 64 | {{/code}} | ||
| 65 | |||
| 66 | Start on newest image Id (as it will have no tags) | ||
| 67 | |||
| 68 | |||
| 69 | {{code}} | ||
| 70 | sudo docker run -d --restart on-failure --name="home-assistant" -v /home/bnp/homeassistant:/config -v /etc/localtime:/etc/localtime:ro --net=host 93627847dd60 | ||
| 71 | {{/code}} | ||
| 72 | |||
| 73 | = Broken Database = | ||
| 74 | |||
| 75 | I got this in the logs | ||
| 76 | |||
| 77 | |||
| 78 | {{code}} | ||
| 79 | csqlite3.DatabaseError: database disk image is malformed | ||
| 80 | |||
| 81 | 2020-06-06T14:53:15.012416986Z sqlalchemy.exc.InvalidRequestError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (sqlite3.DatabaseError) database disk image is malformed | ||
| 82 | 2020-06-06T14:53:15.012430430Z [SQL: INSERT INTO events (event_type, event_data, origin, time_fired, created, context_id, context_user_id) VALUES (?, ?, ?, ?, ?, ?, ?)] | ||
| 83 | 2020-06-06T14:53:15.012443081Z [parameters: ('state_changed', '{"entity_id": "sensor.hue_dimmer_switch_1_battery_level", "old_state": {"entity_id": "sensor.hue_dimmer_switch_1_battery_level", "state": "85", "attr ... (573 characters truncated) ... :00", "last_updated": "2020-06-06T14:53:14.119122+00:00", "context": {"id": "5ab6a95ba76548ea9d3833e194cce998", "parent_id": null, "user_id": null}}}', 'LOCAL', '2020-06-06 14:53:14.119249', '2020-06-06 14:53:14.138770', '5ab6a95ba76548ea9d3833e194cce998', None)] | ||
| 84 | 2020-06-06T14:53:15.012461907Z (Background on this error at: http://sqlalche.me/e/4xp6) (Background on this error at: http://sqlalche.me/e/7s2a) | ||
| 85 | {{/code}} | ||
| 86 | |||
| 87 | Fixed by [[this>>https://community.home-assistant.io/t/db-image-malformed-how-to-fix-it/76413/4]] | ||
| 88 | |||
| 89 | |||
| 90 | {{code}} | ||
| 91 | docker stop "home-assistant" | ||
| 92 | apt-get install sqlite3 | ||
| 93 | sqlite3 ./home-assistant_v2.db ".dump" | sqlite3 ./home-assistant_v2.db.fix | ||
| 94 | mv ./home-assistant_v2.db ./home-assistant_v2.db.broken | ||
| 95 | mv ./home-assistant_v2.db.fix ./home-assistant_v2.db | ||
| 96 | docker start "home-assistant" | ||
| 97 | docker logs --tail 50 --follow --timestamps "home-assistant" | ||
| 98 | {{/code}} | ||
| 99 | |||
| 100 | No Errors in the logs | ||
| 101 | |||
| 102 | = MQTT = | ||
| 103 | |||
| 104 | Start a MQTT Docker instance | ||
| 105 | |||
| 106 | |||
| 107 | {{code}} | ||
| 108 | docker run --init --restart on-failure --name mqtt --restart=always --net=host -p 1883:1883 -d ansi/mosquitto | ||
| 109 | {{/code}} | ||
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | = Postgres = | ||
| 114 | |||
| 115 | Expand [[Home Assistant with Postgres in docker>>Main.information-technology.home-assistant.home-assistant-with-postgres-in-docker]] |