Class DockerLinuxContainerRuntime
java.lang.Object
org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.OCIContainerRuntime
org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.DockerLinuxContainerRuntime
- All Implemented Interfaces:
LinuxContainerRuntime,ContainerRuntime
This class is an extension of OCIContainerRuntime that uses the
native container-executor binary via a
PrivilegedOperationExecutor instance to launch processes inside
Docker containers.
The following environment variables are used to configure the Docker engine:
-
YARN_CONTAINER_RUNTIME_TYPEultimately determines whether a Docker container will be used. If the value isdocker, a Docker container will be used. Otherwise a regular process tree container will be used. This environment variable is checked by theisDockerContainerRequested(org.apache.hadoop.conf.Configuration, java.util.Map<java.lang.String, java.lang.String>)method, which is called by theDelegatingLinuxContainerRuntime. -
YARN_CONTAINER_RUNTIME_DOCKER_IMAGEnames which image will be used to launch the Docker container. -
YARN_CONTAINER_RUNTIME_DOCKER_RUN_OVERRIDE_DISABLEcontrols whether the Docker container's default command is overridden. When set totrue, the Docker container's command will bebash <path_to_launch_script>. When unset or set tofalsethe Docker container's default command is used. -
YARN_CONTAINER_RUNTIME_DOCKER_CONTAINER_NETWORKsets the network type to be used by the Docker container. It must be a valid value as determined by theyarn.nodemanager.runtime.linux.docker.allowed-container-networksproperty. -
YARN_CONTAINER_RUNTIME_DOCKER_PORTS_MAPPINGallows users to specify ports mapping for the bridge network Docker container. The value of the environment variable should be a comma-separated list of ports mapping. It's the same to "-p" option for the Docker run command. If the value is empty, "-P" will be added. -
YARN_CONTAINER_RUNTIME_DOCKER_CONTAINER_PID_NAMESPACEcontrols which PID namespace will be used by the Docker container. By default, each Docker container has its own PID namespace. To share the namespace of the host, theyarn.nodemanager.runtime.linux.docker.host-pid-namespace.allowedproperty must be set totrue. If the host PID namespace is allowed and this environment variable is set tohost, the Docker container will share the host's PID namespace. No other value is allowed. -
YARN_CONTAINER_RUNTIME_DOCKER_CONTAINER_HOSTNAMEsets the hostname to be used by the Docker container. If not specified, a hostname will be derived from the container ID and set as default hostname for networks other than 'host'. -
YARN_CONTAINER_RUNTIME_DOCKER_RUN_PRIVILEGED_CONTAINERcontrols whether the Docker container is a privileged container. In order to use privileged containers, theyarn.nodemanager.runtime.linux.docker.privileged-containers.allowedproperty must be set totrue, and the application owner must appear in the value of theyarn.nodemanager.runtime.linux.docker.privileged-containers.aclproperty. If this environment variable is set totrue, a privileged Docker container will be used if allowed. No other value is allowed, so the environment variable should be left unset rather than setting it to false. -
YARN_CONTAINER_RUNTIME_DOCKER_MOUNTSallows users to specify additional volume mounts for the Docker container. The value of the environment variable should be a comma-separated list of mounts. All such mounts must be given assource:dest[:mode]and the mode must be "ro" (read-only) or "rw" (read-write) to specify the type of access being requested. If neither is specified, read-write will be assumed. The mode may include a bind propagation option. In that case, the mode should either be of the form [option], rw+[option], or ro+[option]. Valid bind propagation options are shared, rshared, slave, rslave, private, and rprivate. The requested mounts will be validated by container-executor based on the values set in container-executor.cfg fordocker.allowed.ro-mountsanddocker.allowed.rw-mounts. -
YARN_CONTAINER_RUNTIME_DOCKER_TMPFS_MOUNTSallows users to specify additional tmpfs mounts for the Docker container. The value of the environment variable should be a comma-separated list of mounts. -
YARN_CONTAINER_RUNTIME_DOCKER_DELAYED_REMOVALallows a user to request delayed deletion of the Docker containers on a per container basis. If true, Docker containers will not be removed until the duration defined byyarn.nodemanager.delete.debug-delay-sechas elapsed. Administrators can disable this feature through the yarn-site propertyyarn.nodemanager.runtime.linux.docker.delayed-removal.allowed. This feature is disabled by default. When this feature is disabled or set to false, the container will be removed as soon as it exits. -
YARN_CONTAINER_RUNTIME_YARN_SYSFS_ENABLEallows export yarn service json to docker container. This feature is disabled by default. When this feature is set, app.json will be available in /hadoop/yarn/sysfs/app.json.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.OCIContainerRuntime
CONTAINER_PID_NAMESPACE_SUFFIX, RUN_PRIVILEGED_CONTAINER_SUFFIX, RUNTIME_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionDockerLinuxContainerRuntime(PrivilegedOperationExecutor privilegedOperationExecutor) Create an instance using the givenPrivilegedOperationExecutorinstance for performing operations.DockerLinuxContainerRuntime(PrivilegedOperationExecutor privilegedOperationExecutor, CGroupsHandler cGroupsHandler) Create an instance using the givenPrivilegedOperationExecutorinstance for performing operations and the givenCGroupsHandlerinstance. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCGroupParentIfRequired(String resourcesOptions, String containerIdStr, DockerRunCommand runCommand) If CGROUPS in enabled and not set to none, then set the CGROUP parent for the command instance.org.apache.hadoop.hdfs.protocol.datatransfer.IOStreamPairPerform docker exec command into running container.getExposedPorts(Container container) Return the exposed ports of the container.String[]getIpAndHost(Container container) Return the host and ip of the container.voidinitialize(org.apache.hadoop.conf.Configuration conf, Context nmContext) Initialize the runtime.static booleanisDockerContainerRequested(org.apache.hadoop.conf.Configuration daemonConf, Map<String, String> env) Return whether the given environment variables indicate that the operation is requesting a Docker container.booleanisRuntimeRequested(Map<String, String> env) Return whether the given environment variables indicate that the operation is requesting this runtime.voidLaunch a container.voidpullImageFromRemote(String containerIdStr, String imageName) voidReap the docker container.voidRelaunch a container.voidSignal the docker container.static voidvalidateImageName(String imageName) Methods inherited from class org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.OCIContainerRuntime
allowHostPidNamespace, allowPrivilegedContainerExecution, formatOciEnvKey, getCsiClients, getGroupIdInfo, getUserIdInfo, initiateCsiClients, isContainerRequestedAsPrivileged, isOCICompliantContainerRequested, mountReadOnlyPath, prepareContainer, validateContainerNetworkType, validateContainerRuntimeType, validateHostnameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.LinuxContainerRuntime
getLocalResources, start, stop
-
Field Details
-
DOCKER_IMAGE_PATTERN
- See Also:
-
ENV_DOCKER_CONTAINER_IMAGE
- See Also:
-
ENV_DOCKER_CONTAINER_CLIENT_CONFIG
- See Also:
-
ENV_DOCKER_CONTAINER_NETWORK
- See Also:
-
ENV_DOCKER_CONTAINER_HOSTNAME
- See Also:
-
ENV_DOCKER_CONTAINER_MOUNTS
- See Also:
-
ENV_DOCKER_CONTAINER_TMPFS_MOUNTS
- See Also:
-
ENV_DOCKER_CONTAINER_DELAYED_REMOVAL
- See Also:
-
ENV_DOCKER_CONTAINER_PORTS_MAPPING
- See Also:
-
ENV_DOCKER_CONTAINER_YARN_SYSFS
- See Also:
-
ENV_DOCKER_CONTAINER_DOCKER_RUNTIME
- See Also:
-
ENV_DOCKER_CONTAINER_DOCKER_SERVICE_MODE
- See Also:
-
ENV_OCI_CONTAINER_PID_NAMESPACE
-
ENV_OCI_CONTAINER_RUN_PRIVILEGED_CONTAINER
-
-
Constructor Details
-
DockerLinuxContainerRuntime
Create an instance using the givenPrivilegedOperationExecutorinstance for performing operations.- Parameters:
privilegedOperationExecutor- thePrivilegedOperationExecutorinstance
-
DockerLinuxContainerRuntime
@VisibleForTesting public DockerLinuxContainerRuntime(PrivilegedOperationExecutor privilegedOperationExecutor, CGroupsHandler cGroupsHandler) Create an instance using the givenPrivilegedOperationExecutorinstance for performing operations and the givenCGroupsHandlerinstance. This constructor is intended for use in testing.- Parameters:
privilegedOperationExecutor- thePrivilegedOperationExecutorinstancecGroupsHandler- theCGroupsHandlerinstance
-
-
Method Details
-
isDockerContainerRequested
public static boolean isDockerContainerRequested(org.apache.hadoop.conf.Configuration daemonConf, Map<String, String> env) Return whether the given environment variables indicate that the operation is requesting a Docker container. If the environment contains a key calledYARN_CONTAINER_RUNTIME_TYPEwhose value isdocker, this method will return true. Otherwise it will return false.- Parameters:
daemonConf- the NodeManager daemon configurationenv- the environment variable settings for the operation- Returns:
- whether a Docker container is requested
-
initialize
public void initialize(org.apache.hadoop.conf.Configuration conf, Context nmContext) throws ContainerExecutionException Description copied from interface:LinuxContainerRuntimeInitialize the runtime.- Specified by:
initializein interfaceLinuxContainerRuntime- Overrides:
initializein classOCIContainerRuntime- Parameters:
conf- theConfigurationto usenmContext- NMContext- Throws:
ContainerExecutionException- if an error occurs while initializing the runtime
-
isRuntimeRequested
Description copied from interface:LinuxContainerRuntimeReturn whether the given environment variables indicate that the operation is requesting this runtime.- Parameters:
env- the environment variable settings for the operation- Returns:
- whether this runtime is requested
-
getCapabilities
-
addCGroupParentIfRequired
@VisibleForTesting protected void addCGroupParentIfRequired(String resourcesOptions, String containerIdStr, DockerRunCommand runCommand) If CGROUPS in enabled and not set to none, then set the CGROUP parent for the command instance.- Parameters:
resourcesOptions- the resource options to check for "cgroups=none"containerIdStr- the container IDrunCommand- the command to set with the CGROUP parent
-
launchContainer
Description copied from interface:ContainerRuntimeLaunch a container.- Parameters:
ctx- theContainerRuntimeContext- Throws:
ContainerExecutionException- if an error occurs while launching the container
-
relaunchContainer
Description copied from interface:ContainerRuntimeRelaunch a container.- Parameters:
ctx- theContainerRuntimeContext- Throws:
ContainerExecutionException- if an error occurs while relaunching the container
-
signalContainer
Signal the docker container. Signals are used to check the liveliness of the container as well as to stop/kill the container. The following outlines the docker container signal handling.- If the null signal is sent, run kill -0 on the pid. This is used to check if the container is still alive, which is necessary for reacquiring containers on NM restart.
- If SIGTERM, SIGKILL is sent, attempt to stop and remove the docker container.
- If the docker container exists and is running, execute docker stop.
- If any other signal is sent, signal the container using docker kill.
- Parameters:
ctx- theContainerRuntimeContext.- Throws:
ContainerExecutionException- if the signaling fails.
-
reapContainer
Reap the docker container.- Parameters:
ctx- theContainerRuntimeContext.- Throws:
ContainerExecutionException- if the removal fails.
-
execContainer
public org.apache.hadoop.hdfs.protocol.datatransfer.IOStreamPair execContainer(ContainerExecContext ctx) throws ContainerExecutionException Perform docker exec command into running container.- Parameters:
ctx- container exec context- Returns:
- IOStreams of docker exec
- Throws:
ContainerExecutionException
-
getIpAndHost
Description copied from interface:ContainerRuntimeReturn the host and ip of the container.- Parameters:
container- theContainer
-
getExposedPorts
Description copied from interface:ContainerRuntimeReturn the exposed ports of the container.- Parameters:
container- theContainer- Returns:
- List of exposed ports
-
validateImageName
- Throws:
ContainerExecutionException
-
pullImageFromRemote
public void pullImageFromRemote(String containerIdStr, String imageName) throws ContainerExecutionException - Throws:
ContainerExecutionException
-