为什么 QDir::exists() 在 docker 容器中不起作用?

Why QDir::exists() do not work in docker container?

在我的主机 KDE Neon 机器(最新升级到 18.04)中执行的以下程序按预期输出 Hello World! 1,而从构建的 Docker 容器执行时输出 Hello World! 0使用下面的 Docker 文件和 运行 sudo docker run -it qdir.

QDir 是否需要 dbus 或其他服务运行?

C++程序:

#include <QDir>
#include <iostream>


int main(int argc [[maybe_unused]], char** argv [[maybe_unused]])
{
    QDir d("/");
    std::cout << "Hello World! " << d.exists() << std::endl;
    return 0;
}

Docker文件:

FROM kdeneon/plasma:user-lts

USER root

RUN apt-get install -y qt5-default

WORKDIR /
COPY qdir /
CMD /bin/bash

编辑, CMakeLists.txt构建程序:

project(qdir)

cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
set(QT_MIN_VERSION "5.3.0")

find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core)

include_directories(${Qt5Core_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})

set(qdir_SRCS main.cpp)

add_executable(qdir ${qdir_SRCS})
target_link_libraries(qdir ${Qt5Core_LIBRARIES})

install(TARGETS qdir RUNTIME DESTINATION bin)

编辑2: 我创建了一个 github 项目,重新组合了上述所有内容。要重现该问题,如果您有 Qt SDK、cmake、ninja 和 docker,只需执行:

git clone https://github.com/kleag/qdirtest
cd qdirtest
./test.sh

这是我得到的输出:

$ ./test.sh
[…]
Successfully built f710cbb7a3c9
Successfully tagged qdir:latest
Hello World! 1
Hello World! 0

我从 apachelogger 那里得到了答案 on KDE forums:

Since 5.10 Qt is using somewhat new syscalls. One of them is statx and last I checked the syscall was not whitelisted in docker, nor was it whitelistable because the libseccomp used for the upstream docker build was too old and didn't know what statx is. Chances are the problem you see is that. If so, seccomp=unconfined would make it work.