You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2018/01/18 00:11:25 UTC

[2/3] mesos git commit: Windows: Mapped the Docker network info types.

Windows: Mapped the Docker network info types.

The Network enum in DockerInfo is specific to Linux containers. `HOST`
doesn't exist on Windows and `BRIDGE` is `NAT` on Windows. The current
default docker network setting was always `HOST`, which broke the
Windows docker executor. Now, if a specific network isn't given, the
network mode will default to `HOST` on Linux agents and `NAT` on Windows
agents. Also, `BRIDGE` mode will be translated to `NAT` on Windows.

Review: https://reviews.apache.org/r/63860/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6b35c93b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6b35c93b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6b35c93b

Branch: refs/heads/master
Commit: 6b35c93baf4445686caea6ca12788fe7593e0dd8
Parents: eccd0a9
Author: Akash Gupta <ak...@hotmail.com>
Authored: Wed Jan 17 13:51:44 2018 -0800
Committer: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Committed: Wed Jan 17 16:11:14 2018 -0800

----------------------------------------------------------------------
 src/docker/docker.cpp | 46 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6b35c93b/src/docker/docker.cpp
----------------------------------------------------------------------
diff --git a/src/docker/docker.cpp b/src/docker/docker.cpp
index 722a54a..3df370e 100644
--- a/src/docker/docker.cpp
+++ b/src/docker/docker.cpp
@@ -738,10 +738,43 @@ Try<Docker::RunOptions> Docker::RunOptions::create(
 
   options.volumeDriver = volumeDriver;
 
-  switch (dockerInfo.network()) {
-    case ContainerInfo::DockerInfo::HOST: options.network = "host"; break;
-    case ContainerInfo::DockerInfo::BRIDGE: options.network = "bridge"; break;
-    case ContainerInfo::DockerInfo::NONE: options.network = "none"; break;
+  ContainerInfo::DockerInfo::Network network;
+  if (dockerInfo.has_network()) {
+    network = dockerInfo.network();
+  } else {
+    // If no network was given, then use the OS specific default.
+#ifdef __WINDOWS__
+    network = ContainerInfo::DockerInfo::BRIDGE;
+#else
+    network = ContainerInfo::DockerInfo::HOST;
+#endif // __WINDOWS__
+  }
+
+  // See https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/container-networking // NOLINT(whitespace/line_length)
+  // and https://docs.docker.com/engine/userguide/networking/ on what network
+  // modes are supported for Windows and Linux docker respectively.
+  switch (network) {
+    case ContainerInfo::DockerInfo::HOST: {
+#ifdef __WINDOWS__
+      return Error("Unsupported Network mode: " + stringify(network));
+#else
+      options.network = "host";
+      break;
+#endif // __WINDOWS__
+    }
+    case ContainerInfo::DockerInfo::BRIDGE: {
+#ifdef __WINDOWS__
+      // Windows "nat" network mode is equivalent to Linux "bridge" mode.
+      options.network = "nat";
+#else
+      options.network = "bridge";
+#endif // __WINDOWS__
+      break;
+    }
+    case ContainerInfo::DockerInfo::NONE: {
+      options.network = "none";
+      break;
+    }
     case ContainerInfo::DockerInfo::USER: {
       if (containerInfo.network_infos_size() == 0) {
         return Error("No network info found in container info");
@@ -752,15 +785,14 @@ Try<Docker::RunOptions> Docker::RunOptions::create(
       }
 
       const NetworkInfo& networkInfo = containerInfo.network_infos(0);
-      if(!networkInfo.has_name()){
+      if (!networkInfo.has_name()) {
         return Error("No network name found in network info");
       }
 
       options.network = networkInfo.name();
       break;
     }
-    default: return Error("Unsupported Network mode: " +
-                          stringify(dockerInfo.network()));
+    default: return Error("Unsupported Network mode: " + stringify(network));
   }
 
   if (containerInfo.has_hostname()) {