I'm having this warning every time I run a script in my Docker container based on Ubuntu focal:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-'
How can I fix it or at least silence it?
I am aware of this issues that says that it's not something one should try to fix. However, it's messing a bit my outputs.
CodePudding user response:
If you want to get rid of the warning, since you are in a container and you are not likely to get the issue that multiple users will have file permission issue, as noted in the question you are linking, then you could simply define an environment variable and make it point to the /tmp directory.
Here is an example using pandoc
and wkhtmltopdf
that normally gives this error:
FROM ubuntu:focal
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -qq \
&& apt-get install --yes pandoc wkhtmltopdf \
&& echo "# Hello world!" > demo.md
ENV XDG_RUNTIME_DIR=/tmp
## ^-- This is the interesting line for you
CMD [ \
"pandoc", \
"demo.md", \
"--output", "demo.pdf", \
"--pdf-engine", "wkhtmltopdf", \
"--metadata", "pagetitle='Demo'" \
]
Without the ENV
, it would yield:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
Loading page (1/2)
Printing pages (2/2)
Done
With it, it would, then, be:
Loading page (1/2)
Printing pages (2/2)
Done
If you want to make it as advised, with a folder /run/user/<UID>
, then you'll have to create the folder and assign it the correct right first.
For containers running as root
:
FROM ubuntu:focal
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -qq \
&& apt-get install --yes pandoc wkhtmltopdf \
&& echo "# Hello world!" > demo.md \
&& mkdir -p -m 0700 /run/user/0
## ^-- now you also have this last line
ENV XDG_RUNTIME_DIR=/run/user/0
## ^-- And still that one
CMD [ \
"pandoc", \
"demo.md", \
"--output", "demo.pdf", \
"--pdf-engine", "wkhtmltopdf", \
"--metadata", "pagetitle='Demo'" \
]
For containers running as another user:
FROM ubuntu:focal
ARG DEBIAN_FRONTEND=noninteractive
ARG UID=1000
WORKDIR /tmp
RUN apt-get update -qq \
&& apt-get install --yes pandoc wkhtmltopdf \
&& echo "# Hello world!" > demo.md \
&& chmod 766 demo.md \
&& useradd --uid "${UID}" user \
&& mkdir -p -m 0700 /run/user/"${UID}" \
&& chown user:user /run/user/"${UID}"
## ^-- and, now, you have those three last lines
USER user
ENV XDG_RUNTIME_DIR=/run/user/"${UID}"
## ^-- And still that one, plus the user definition, of course
CMD [ \
"pandoc", \
"demo.md", \
"--output", "demo.pdf", \
"--pdf-engine", "wkhtmltopdf", \
"--metadata", "pagetitle='Demo'" \
]