You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2017/02/17 01:50:55 UTC
[3/7] mesos git commit: Added Windows support for Docker executor.
Added Windows support for Docker executor.
This commit will introduce the changes to the Mesos Docker interfaces
required to use the Docker executor to run Windows Containers in the
Mesos agent. In particular, since Windows Containers use named pipes to
connect do the Docker host, rather than a socket, we introduce the
plumbing to default to a named pipe connection when invoking the
`docker` command.
This work constitutes the beginning of the end of the work that will
eventually result in Mesos support of Windows Containers.
This review is partially based on r/52364, which was the work of Daniel
Pravat.
Review: https://reviews.apache.org/r/56505/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/7a6b7c69
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/7a6b7c69
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/7a6b7c69
Branch: refs/heads/master
Commit: 7a6b7c69560178a22be7a6f0990b27556fca2c59
Parents: 83c564c
Author: Daniel Pravat <dp...@outlook.com>
Authored: Wed Feb 15 16:21:39 2017 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Thu Feb 16 17:50:09 2017 -0800
----------------------------------------------------------------------
src/docker/docker.cpp | 9 +++++++++
src/docker/docker.hpp | 13 ++++++++++++-
src/docker/executor.hpp | 6 ++++--
src/slave/constants.hpp | 8 ++++++++
src/slave/containerizer/docker.cpp | 3 ++-
src/slave/flags.cpp | 10 ++++++----
src/tests/flags.hpp | 16 +++++++++++-----
7 files changed, 52 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/7a6b7c69/src/docker/docker.cpp
----------------------------------------------------------------------
diff --git a/src/docker/docker.cpp b/src/docker/docker.cpp
index 68042fd..9a454ec 100755
--- a/src/docker/docker.cpp
+++ b/src/docker/docker.cpp
@@ -104,9 +104,18 @@ Try<Owned<Docker>> Docker::create(
bool validate,
const Option<JSON::Object>& config)
{
+#ifndef __WINDOWS__
+ // TODO(hausdorff): Currently, `path::absolute` does not handle all the edge
+ // cases of Windows. Revisit this when MESOS-3442 is resolved.
+ //
+ // NOTE: When we do come back and fix this bug, it is also worth noting that
+ // on Windows an empty value of `socket` is frequently used to connect to the
+ // Docker host (i.e., the user wants to connect 'npipes://', with an empty
+ // socket path). A full solution should accommodate this.
if (!path::absolute(socket)) {
return Error("Invalid Docker socket path: " + socket);
}
+#endif // __WINDOWS__
Owned<Docker> docker(new Docker(path, socket, config));
if (!validate) {
http://git-wip-us.apache.org/repos/asf/mesos/blob/7a6b7c69/src/docker/docker.hpp
----------------------------------------------------------------------
diff --git a/src/docker/docker.hpp b/src/docker/docker.hpp
index 9093371..314fcb4 100644
--- a/src/docker/docker.hpp
+++ b/src/docker/docker.hpp
@@ -38,6 +38,17 @@
#include "mesos/resources.hpp"
+// OS-specific default prefix to be used for the DOCKER_HOST environment
+// variable. Note that on Linux, the default prefix is the only prefix
+// available; only Windows supports multiple prefixes.
+// TODO(hausdorff): Add support for the Windows `tcp://` prefix as well.
+#ifdef __WINDOWS__
+constexpr char DEFAULT_DOCKER_HOST_PREFIX[] = "npipe://";
+#else
+constexpr char DEFAULT_DOCKER_HOST_PREFIX[] = "unix://";
+#endif // __WINDOWS__
+
+
// Abstraction for working with Docker (modeled on CLI).
//
// TODO(benh): Make futures returned by functions be discardable.
@@ -212,7 +223,7 @@ protected:
const std::string& _socket,
const Option<JSON::Object>& _config)
: path(_path),
- socket("unix://" + _socket),
+ socket(DEFAULT_DOCKER_HOST_PREFIX + _socket),
config(_config) {}
private:
http://git-wip-us.apache.org/repos/asf/mesos/blob/7a6b7c69/src/docker/executor.hpp
----------------------------------------------------------------------
diff --git a/src/docker/executor.hpp b/src/docker/executor.hpp
index 8385631..d424977 100644
--- a/src/docker/executor.hpp
+++ b/src/docker/executor.hpp
@@ -45,8 +45,10 @@ struct Flags : public virtual mesos::internal::logging::Flags
add(&Flags::docker_socket,
"docker_socket",
- "The UNIX socket path to be used by docker CLI for accessing docker\n"
- "daemon.");
+ "Resource used by the agent and the executor to provice CLI access\n"
+ "to the Docker daemon. On Unix, this is typically a path to a\n"
+ "socket, such as '/var/run/docker.sock'. On Windows this must be a\n"
+ "named pipe, such as '//./pipe/docker_engine'.");
add(&Flags::sandbox_directory,
"sandbox_directory",
http://git-wip-us.apache.org/repos/asf/mesos/blob/7a6b7c69/src/slave/constants.hpp
----------------------------------------------------------------------
diff --git a/src/slave/constants.hpp b/src/slave/constants.hpp
index 1159ac3..725689a 100644
--- a/src/slave/constants.hpp
+++ b/src/slave/constants.hpp
@@ -98,6 +98,14 @@ constexpr Bytes DEFAULT_EXECUTOR_MEM = Megabytes(32);
constexpr uint16_t DEFAULT_EPHEMERAL_PORTS_PER_CONTAINER = 1024;
#endif
+// Default UNIX socket (Linux) or Named Pipe (Windows) resource that provides
+// CLI access to the Docker daemon.
+#ifdef __WINDOWS__
+constexpr char DEFAULT_DOCKER_HOST_RESOURCE[] = "//./pipe/docker_engine";
+#else
+constexpr char DEFAULT_DOCKER_HOST_RESOURCE[] = "/var/run/docker.sock";
+#endif // __WINDOWS__
+
// Default duration that docker containers will be removed after exit.
constexpr Duration DOCKER_REMOVE_DELAY = Hours(6);
http://git-wip-us.apache.org/repos/asf/mesos/blob/7a6b7c69/src/slave/containerizer/docker.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/docker.cpp b/src/slave/containerizer/docker.cpp
index 886528f..1791108 100644
--- a/src/slave/containerizer/docker.cpp
+++ b/src/slave/containerizer/docker.cpp
@@ -37,6 +37,7 @@
#include <stout/hashset.hpp>
#include <stout/jsonify.hpp>
#include <stout/os.hpp>
+#include <stout/path.hpp>
#include <stout/uuid.hpp>
#include <stout/os/killtree.hpp>
@@ -91,7 +92,7 @@ const string DOCKER_NAME_SEPERATOR = ".";
// Declared in header, see explanation there.
-const string DOCKER_SYMLINK_DIRECTORY = "docker/links";
+const string DOCKER_SYMLINK_DIRECTORY = path::join("docker", "links");
#ifdef __WINDOWS__
http://git-wip-us.apache.org/repos/asf/mesos/blob/7a6b7c69/src/slave/flags.cpp
----------------------------------------------------------------------
diff --git a/src/slave/flags.cpp b/src/slave/flags.cpp
index 71935de..8de2643 100644
--- a/src/slave/flags.cpp
+++ b/src/slave/flags.cpp
@@ -632,10 +632,12 @@ mesos::internal::slave::Flags::Flags()
add(&Flags::docker_socket,
"docker_socket",
- "The UNIX socket path to be mounted into the docker executor container\n"
- "to provide docker CLI access to the docker daemon. This must be the\n"
- "path used by the agent's docker image.\n",
- "/var/run/docker.sock");
+ "Resource used by the agent and the executor to provice CLI access\n"
+ "to the Docker daemon. On Unix, this is typically a path to a\n"
+ "socket, such as '/var/run/docker.sock'. On Windows this must be a\n"
+ "named pipe, such as '//./pipe/docker_engine'. NOTE: This must be\n"
+ "the path used by the Docker image used to run the agent.\n",
+ DEFAULT_DOCKER_HOST_RESOURCE);
add(&Flags::docker_config,
"docker_config",
http://git-wip-us.apache.org/repos/asf/mesos/blob/7a6b7c69/src/tests/flags.hpp
----------------------------------------------------------------------
diff --git a/src/tests/flags.hpp b/src/tests/flags.hpp
index cab2416..9bfe7be 100644
--- a/src/tests/flags.hpp
+++ b/src/tests/flags.hpp
@@ -26,10 +26,15 @@
#include <stout/os.hpp>
#include "common/parse.hpp"
+
#include "logging/logging.hpp"
+
#include "master/constants.hpp"
+
#include "messages/messages.hpp"
+#include "slave/constants.hpp"
+
namespace mesos {
namespace internal {
namespace tests {
@@ -77,11 +82,12 @@ public:
add(&Flags::docker_socket,
"docker_socket",
- "The UNIX socket path to be mounted into the\n"
- "docker executor container to provide docker\n"
- "CLI access to the docker daemon. This must be the\n"
- "path used by the agent's docker image.\n",
- "/var/run/docker.sock");
+ "Resource used by the agent and the executor to provice CLI access\n"
+ "to the Docker daemon. On Unix, this is typically a path to a\n"
+ "socket, such as '/var/run/docker.sock'. On Windows this must be a\n"
+ "named pipe, such as '//./pipe/docker_engine'. NOTE: This must be\n"
+ "the path used by the Docker image used to run the agent.\n",
+ slave::DEFAULT_DOCKER_HOST_RESOURCE);
// This help message for --modules flag is the same for
// {master,slave,sched,tests}/flags.[ch]pp and should always be kept in