forked from qt-creator/qt-creator
Docker: Add "isContainerRunning"
Change-Id: I2e22f5fb0ed86b0f7d61dc47c23696c00ec875ea Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -54,6 +54,26 @@ bool DockerApi::canConnect()
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DockerApi::isContainerRunning(const QString &containerId)
|
||||
{
|
||||
Process process;
|
||||
FilePath dockerExe = dockerClient();
|
||||
if (dockerExe.isEmpty() || !dockerExe.isExecutableFile())
|
||||
return false;
|
||||
|
||||
process.setCommand(
|
||||
CommandLine(dockerExe, QStringList{"inspect", "--format", "{{.State.Running}}", containerId}));
|
||||
process.runBlocking();
|
||||
|
||||
if (process.result() == ProcessResult::FinishedWithSuccess) {
|
||||
QString output = process.readAllStandardOutput().trimmed();
|
||||
if (output == "true")
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DockerApi::checkCanConnect(bool async)
|
||||
{
|
||||
if (async) {
|
||||
|
@@ -44,6 +44,8 @@ public:
|
||||
static void recheckDockerDaemon();
|
||||
QFuture<Utils::expected_str<QList<Network>>> networks();
|
||||
|
||||
bool isContainerRunning(const QString &containerId);
|
||||
|
||||
signals:
|
||||
void dockerDaemonAvailableChanged();
|
||||
|
||||
|
Reference in New Issue
Block a user