From f2c501a5bfa4637bfd96671bfe2c62d65247c542 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Wed, 22 Sep 2021 10:31:06 +0200 Subject: [PATCH] Docker: Tweak handling of DISPLAY Passing the DISPLAY variable differently on Windows allows to even run a gui application on the docker image if there is an XServer (e.g. vcxsrv) running on the Windows host that can be used. Change-Id: I36f849c4efc6e53ef92fcea96b4b256fd92a01c6 Reviewed-by: hjk Reviewed-by: David Schulz --- src/plugins/docker/dockerdevice.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index c612e85a925..b71fccd41ec 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -68,7 +68,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -772,6 +774,20 @@ void DockerDevicePrivate::stopCurrentContainer() proc.runBlocking(); } +static QString getLocalIPv4Address() +{ + const QList addresses = QNetworkInterface::allAddresses(); + for (auto &a : addresses) { + if (a.isInSubnet(QHostAddress("192.168.0.0"), 16)) + return a.toString(); + if (a.isInSubnet(QHostAddress("10.0.0.0"), 8)) + return a.toString(); + if (a.isInSubnet(QHostAddress("172.16.0.0"), 12)) + return a.toString(); + } + return QString(); +} + void DockerDevicePrivate::startContainer() { QString tempFileName; @@ -782,9 +798,11 @@ void DockerDevicePrivate::startContainer() tempFileName = temp.fileName(); } + const QString display = HostOsInfo::isWindowsHost() ? QString(getLocalIPv4Address() + ":0.0") + : QString(":0"); CommandLine dockerRun{"docker", {"run", "-i", "--cidfile=" + tempFileName, "--rm", - "-e", "DISPLAY=:0", + "-e", QString("DISPLAY=%1").arg(display), "-e", "XAUTHORITY=/.Xauthority", "--net", "host"}};