On my system /var/log is on ramdisk in order to avoid writes to my SD card. By default, the Home Assistant container writes logs to /etc/homeassistant/home-assistant.log, that’s nonstandard and incorrect on Linux systems.
One can redirect the log file like this:
Let systemd-tmpfiles know that Home Assistant needs a folder in /var/log on each boot. Open /etc/tmpfiles.d/home-assistant.conf and add these line, save it:
d /var/log/homeassistant 0755 root root - -
f /etc/homeassistant/home-assistant.log 0644 root root - -
Create the container with the log mounted into the correct location, the important addition is -v /var/log/homeassistant/home-assistant.log:/config/home-assistant.log
If you haven’t yet instructed systemd-tmpfiles to create /var/log/homeassistant/homeassistant.log make sure to do it manually, otherwise Docker will try to be smart and create homeassistant.log as a directory .
sudo docker run --init -d --name="home-assistant" -e "TZ=[your timezone]" -v /etc/homeassistant:/config -v /var/log/homeassistant/home-assistant.log:/config/home-assistant.log [fill in the rest according to your container configuration and the documentation]
(Before you ask, no, just a symlink from /etc/homeassistant to /var/log doesn’t work)
If you haven’t, you probably also wish to instruct Docker to use journald or rsyslog as its logging destination, Docker too creates its own log file.
That’s docker’s log in /var/lib/docker/containers/{container hash}/{something}.log, yes that disappears nicely after Docker has been reconfigured, however it does not affect the home-assistant.log file that’s created in /config/home-assistant.log (mounted to /etc/homeassistant/). Because even if Docker itself is instructed otherwise that file is created by Home Assistant and it’s mandatory.
If you’re writing a Community Guide, it’s preferable to avoid including personal opinions and similar editorializing. It’s a guide, not an op-ed.
For example, I removed your original statement about how you found the default configuration to be “annoying”. You subsequently felt the need to amend it and add “that’s not good”.
“Annoying” and “that’s not good” are opinions based on your specific requirements. There’s nothing inherently wrong with the file’s location; it’s consistent with other installation methods.
If you feel strongly about the file’s location, compose a regular post, or a Feature Request, expressing your opinions and why it should be located elsewhere.
Actually you’re incorrect. /etc is rather officially not for logs, yet that is the recommended default. I could have written it much more sternly what I think of nonstandard behaviour than just “annoying”.
That doesn’t justify editorializing within a Community Guide. Simply compose a Feature Request suggesting it be relocated to comply with logging standards.
If you believe it fails to comply with logging standards, simply state that (with a link to a reference supporting the claim). That serves to educate the reader far better than expressing a personal opinion about its location.
EDIT
… and you’ve amended your post accordingly. Thank you!
But that gave the following error:
ERROR: for xxxxxxxx_homeassistant Cannot start service homeassistant: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting “/var/log/homeassistant/home-assistant.log” to rootfs at “/config/home-assistant.log” caused: mount through procfd: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Do I have to use something else instead of volumes (-v stands for volume in your example ) to ‘mount’ a file?
Gave this a try and have been unsuccessful. Docker container does not start.
$ docker start homeassistant
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting “/var/log/home-assistant.log” to rootfs at “/config/home-assistant.log”: mount /var/log/home-assistant.log:/config/home-assistant.log (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Error: failed to start containers: homeassistant
$ cat /etc/tmpfiles.d/home-assistant.conf
d /var/log/homeassistant.log 0755 root root - -
f /srv/homeassistant/home-assistant.log 0644 root root - -
I’m not sure if this quite what you want, but using docker compose I have my home assistant logs being pushed to the local file system, as well as having the configuration being read from the local file system. I’ll release a tutorial in 3-6 months when it’s all stable and tested, but the important part is the volume mapping below