diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java index 33b8addb70..a3aff2ff59 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java @@ -146,6 +146,8 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime { public static final String ENV_DOCKER_CONTAINER_LOCAL_RESOURCE_MOUNTS = "YARN_CONTAINER_RUNTIME_DOCKER_LOCAL_RESOURCE_MOUNTS"; + static final String CGROUPS_ROOT_DIRECTORY = "/sys/fs/cgroup"; + private Configuration conf; private DockerClient dockerClient; private PrivilegedOperationExecutor privilegedOperationExecutor; @@ -437,7 +439,6 @@ public void launchContainer(ContainerRuntimeContext ctx) LOCALIZED_RESOURCES); @SuppressWarnings("unchecked") List userLocalDirs = ctx.getExecutionAttribute(USER_LOCAL_DIRS); - Set capabilities = new HashSet<>(Arrays.asList(conf.getStrings( YarnConfiguration.NM_DOCKER_CONTAINER_CAPABILITIES, YarnConfiguration.DEFAULT_NM_DOCKER_CONTAINER_CAPABILITIES))); @@ -449,7 +450,8 @@ public void launchContainer(ContainerRuntimeContext ctx) .setContainerWorkDir(containerWorkDir.toString()) .setNetworkType(network) .setCapabilities(capabilities) - .addMountLocation("/sys/fs/cgroup", "/sys/fs/cgroup:ro", false); + .addMountLocation(CGROUPS_ROOT_DIRECTORY, + CGROUPS_ROOT_DIRECTORY + ":ro", false); List allDirs = new ArrayList<>(containerLocalDirs); allDirs.addAll(filecacheDirs); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java index a05ff46f9e..32533940fc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java @@ -257,6 +257,18 @@ private String getExpectedTestCapabilitiesArgumentString() { return expectedCapabilitiesString.toString(); } + private String getExpectedCGroupsMountString() { + boolean cGroupsMountExists = new File( + DockerLinuxContainerRuntime.CGROUPS_ROOT_DIRECTORY).exists(); + + if(cGroupsMountExists) { + return "-v " + DockerLinuxContainerRuntime.CGROUPS_ROOT_DIRECTORY + + ":" + DockerLinuxContainerRuntime.CGROUPS_ROOT_DIRECTORY + ":ro "; + } else { + return ""; + } + } + @Test public void testDockerContainerLaunch() throws ContainerExecutionException, PrivilegedOperationException, @@ -276,7 +288,7 @@ public void testDockerContainerLaunch() .append("--workdir=%3$s ") .append("--net=host ") .append(getExpectedTestCapabilitiesArgumentString()) - .append("-v /sys/fs/cgroup:/sys/fs/cgroup:ro ") + .append(getExpectedCGroupsMountString()) .append("-v %4$s:%4$s ") .append("-v %5$s:%5$s ") .append("-v %6$s:%6$s ") @@ -382,7 +394,7 @@ public void testContainerLaunchWithNetworkingDefaults() .append("--workdir=%3$s ") .append("--net=" + allowedNetwork + " ") .append(getExpectedTestCapabilitiesArgumentString()) - .append("-v /sys/fs/cgroup:/sys/fs/cgroup:ro ") + .append(getExpectedCGroupsMountString()) .append("-v %4$s:%4$s ").append("-v %5$s:%5$s ") .append("-v %6$s:%6$s ").append("-v %7$s:%7$s ") .append("-v %8$s:%8$s ").append("%9$s ") @@ -437,7 +449,7 @@ public void testContainerLaunchWithCustomNetworks() .append("--workdir=%3$s ") .append("--net=" + customNetwork1 + " ") .append(getExpectedTestCapabilitiesArgumentString()) - .append("-v /sys/fs/cgroup:/sys/fs/cgroup:ro ") + .append(getExpectedCGroupsMountString()) .append("-v %4$s:%4$s ").append("-v %5$s:%5$s ") .append("-v %6$s:%6$s ").append("-v %7$s:%7$s ") .append("-v %8$s:%8$s ").append("%9$s ") @@ -474,7 +486,7 @@ public void testContainerLaunchWithCustomNetworks() .append("--workdir=%3$s ") .append("--net=" + customNetwork2 + " ") .append(getExpectedTestCapabilitiesArgumentString()) - .append("-v /sys/fs/cgroup:/sys/fs/cgroup:ro ") + .append(getExpectedCGroupsMountString()) .append("-v %4$s:%4$s ").append("-v %5$s:%5$s ") .append("-v %6$s:%6$s ").append("-v %7$s:%7$s ") .append("-v %8$s:%8$s ").append("%9$s ")