diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c index cba84aca17..1e117b69c8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c @@ -3206,12 +3206,15 @@ int remove_docker_container(char**argv, int argc) { const char *container_id = NULL; int start_index = 0; + char **args = alloc_and_clear_memory(argc + 1, sizeof(char *)); + args[0] = "-f"; if (argc == 2) { yarn_hierarchy = argv[0]; container_id = argv[1]; // Skip the yarn_hierarchy argument for exec_docker_command start_index = 1; } + args[1] = argv[start_index]; pid_t child_pid = fork(); if (child_pid == -1) { @@ -3222,15 +3225,15 @@ int remove_docker_container(char**argv, int argc) { } if (child_pid == 0) { // child - int rc = exec_docker_command("rm", argv + start_index, argc - start_index); - return rc; // Only get here if exec fails - + int rc = exec_docker_command("rm", args, 2); + exit_code = rc; // Only get here if exec fails } else { // parent exit_code = wait_and_get_exit_code(child_pid); if (exit_code != 0) { exit_code = DOCKER_RUN_FAILED; } } + free(args); // Clean up cgroups if necessary if (yarn_hierarchy != NULL) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/utils/docker-util.c b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/utils/docker-util.c index 1339c679a3..90d96bb664 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/utils/docker-util.c +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/utils/docker-util.c @@ -722,11 +722,19 @@ int get_docker_rm_command(const char *command_file, const struct configuration * } ret = add_to_args(args, DOCKER_RM_COMMAND); - if (ret == 0) { - ret = add_to_args(args, container_name); - if (ret != 0) { - ret = BUFFER_TOO_SMALL; - } + if (ret != 0) { + ret = BUFFER_TOO_SMALL; + goto free_and_exit; + } + ret = add_to_args(args, "-f"); + if (ret != 0) { + ret = BUFFER_TOO_SMALL; + goto free_and_exit; + } + ret = add_to_args(args, container_name); + if (ret != 0) { + ret = BUFFER_TOO_SMALL; + goto free_and_exit; } free_and_exit: free(container_name); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/utils/test_docker_util.cc b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/utils/test_docker_util.cc index d8f609d18f..f57413e066 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/utils/test_docker_util.cc +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/utils/test_docker_util.cc @@ -304,7 +304,7 @@ namespace ContainerExecutor { file_cmd_vec.push_back( std::make_pair( "[docker-command-execution]\n docker-command=rm\n name=container_e1_12312_11111_02_000001", - "rm container_e1_12312_11111_02_000001")); + "rm -f container_e1_12312_11111_02_000001")); std::vector > bad_file_cmd_vec; bad_file_cmd_vec.push_back(std::make_pair( @@ -1711,7 +1711,7 @@ namespace ContainerExecutor { "/usr/bin/docker --config=/my-config pull image-id")); input_output_map.push_back(std::make_pair( "[docker-command-execution]\n docker-command=rm\n docker-config=/my-config\n name=container_e1_12312_11111_02_000001", - "/usr/bin/docker --config=/my-config rm container_e1_12312_11111_02_000001")); + "/usr/bin/docker --config=/my-config rm -f container_e1_12312_11111_02_000001")); input_output_map.push_back(std::make_pair( "[docker-command-execution]\n docker-command=stop\n docker-config=/my-config\n name=container_e1_12312_11111_02_000001", "/usr/bin/docker --config=/my-config stop container_e1_12312_11111_02_000001"));