How to allow python script to access a root-owned docker container log file?
I wrote a short python program (one script with ~100 lines) that basically tracks the log of a running docker container located in:
/var/lib/docker/containers/7d847e/7d847e-json.log
, where 7d847e
is the container id.
However, the path /var/lib/docker/containers/
is owned by root. I tail
the log file in command line with sudo tail -f ...
, but how can I make the python script access the file?
I can think of the following ways:
- change the owner of
/var/lib/docker/containers/
to me; (not sure if this breaks other stuff) - save the sudo password somewhere and allow the python script to access it
They both look like bad idea to me.
What is the best practice?
Source: Docker Questions