Docker: Use host.docker.internal

DockerDesktop on Windows and macOS provide the hostname
host.docker.internal to reach the host machine. We use that as its
more likely to work for different setups than trying to figure out
the host ip yourself.

Change-Id: I9f594d0e97e7f35ceb580ac3e3304de999bfea9c
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Marcus Tillmanns
2022-10-14 10:01:46 +02:00
parent 3499cd79c7
commit 742f92d246

View File

@@ -479,20 +479,6 @@ void DockerDevicePrivate::stopCurrentContainer()
m_cachedEnviroment.clear();
}
static QString getLocalIPv4Address()
{
const QList<QHostAddress> 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();
}
bool DockerDevicePrivate::prepareForBuild(const Target *target)
{
QTC_ASSERT(QThread::currentThread() == thread(), return false);
@@ -574,7 +560,7 @@ bool DockerDevicePrivate::createContainer()
return false;
const QString display = HostOsInfo::isLinuxHost() ? QString(":0")
: QString(getLocalIPv4Address() + ":0.0");
: QString("host.docker.internal:0");
CommandLine dockerCreate{m_settings->dockerBinaryPath.filePath(),
{"create",
"-i",