gpt4 book ai didi

docker - 我可以静音 QStandardPaths : XDG_RUNTIME_DIR not set, 默认为 '/tmp/runtime-'

转载 作者:行者123 更新时间:2023-12-04 18:42:30 24 4
gpt4 key购买 nike

每次我在基于 Ubuntu 焦点的 Docker 容器中运行脚本时都会收到此警告:

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-'
我该如何解决它或至少让它静音?
我知道 this issues这表示这不是一个应该尝试解决的问题。但是,这有点弄乱我的输出。

最佳答案

如果您想摆脱警告,因为您在一个容器中并且您不太可能遇到多个用户将具有文件权限问题的问题,如您正在链接的问题中所述,那么您可以简单地定义一个环境变量并使其指向/tmp 目录。
这是一个使用 pandoc 的示例和 wkhtmltopdf通常会出现此错误:

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'" \
]
没有 ENV ,它将产生:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
Loading page (1/2)
Printing pages (2/2)
Done
有了它,它将是:
Loading page (1/2)
Printing pages (2/2)
Done

如果您想按照建议进行操作,请使用文件夹 /run/user/<UID> ,那么您必须先创建文件夹并为其分配正确的权限。
对于以 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'" \
]
对于以另一个用户身份运行的容器:
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'" \
]

关于docker - 我可以静音 QStandardPaths : XDG_RUNTIME_DIR not set, 默认为 '/tmp/runtime-',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71571296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com