Kill a running container

    :type container: string
    :param container: The container id to kill

    :rtype: dict
    :returns: boolean
343423
def kill(config, container, *args, **kwargs):
    '''
    
    '''
    err = "Unknown"
    client = _get_client(config)
    try:
        dcontainer = _get_container_infos(config, container)['Id']
        if is_running(config, dcontainer):
            client.kill(dcontainer)
            if not is_running(config, dcontainer):
                print "Container killed."
                return True
        else:
            print "Container not running."
            return True
    except Exception as e:
        err = e
    utils.error("Unable to kill the container: %s"%err)
    return False
375886
def stop_cmd(self, name, force):
        
        check_permissions()

        if name:
            echo("Would stop container {0}".format(name))
        else:
            echo("Would stop all containers")
        echo("For now use 'docker stop' to stop the containers")
394774
async def _handle_container_hard_timeout(self, container_id, hard_timeout):
        
        if container_id in self._watching:
            self._logger.info("Killing container %s as it used its %i wall time seconds",
                              container_id, hard_timeout)
            await self._kill_it_with_fire(container_id)
1332137
def kill(self):
        
        if self.running():
            if self.verbose:
                print('Killing {} with PID {}'.format(self.exe, self.process.pid))
            self.process.kill()

            # Threads *should* tidy up after themselves, but we do it explicitly
            self.join_threads()
80710
def dockerKill(container_name, client, gentleKill=False):
    
    try:
        this_container = client.containers.get(container_name)
        while this_container.status == 'running':
            if gentleKill is False:
                client.containers.get(container_name).kill()
            else:
                client.containers.get(container_name).stop()
            this_container = client.containers.get(container_name)
    except NotFound:
        logger.debug("Attempted to stop container, but container != exist: ",
                      container_name)
    except requests.exceptions.HTTPError as e:
        logger.debug("Attempted to stop container, but server gave an error: ",
                      container_name)
        raise create_api_error_from_http_exception(e)
604634
def remove_container(config, container=None, force=True, v=False, *args, **kwargs):
    '''
    
    '''
    err = "Unknown"
    client = _get_client(config)
    dcontainer = None
    try:
        try:
            dcontainer = _get_container_infos(config, container)['Id']
        except Exception:
#            print "Container not existing."
            return True
        else:
            if not dcontainer:
                return True
            if is_running(config, dcontainer):
                if not force:
                    utils.error("Container running, won't remove it.")
                    return False
                else:
                    kill(config, dcontainer)
            client.remove_container(dcontainer, v=v)
            try:
                infos = _get_container_infos(config, dcontainer)
                if not infos:
                    return True
            except Exception:
#                print "Container has been successfully removed."
                return True
    except Exception as e:
        err = e
    utils.error("Unable to remove container: %s"%err)
    return False
710114
def unpause(self, container):
        
        url = self._url('/containers/{0}/unpause', container)
        res = self._post(url)
        self._raise_for_status(res)
555037
def destroy(force=false)
      unless exists?
        raise ContainerError, "Container does not exist."
      end

      if running?
        if force == true
          stop
        else
          raise ContainerError, "Container is running. Stop it first or use force=true"
        end  
      end

      run("destroy")

      !exists?
    end
1180406
def terminate(self, container):
        
        self._client_chk.check(container)
        args = {
            'container': int(container),
        }
        response = self._client.raw('corex.terminate', args)

        result = response.get()
        if result.state != 'SUCCESS':
            raise RuntimeError('failed to terminate container: %s' % result.data)
126910
def kill
      return false unless hostname == Socket.gethostname
      begin
        Process.kill('KILL', pid)
        self.state = "killed"
        self.save!
      rescue Errno::ESRCH
        puts "pid #{pid} does not exist!"
        mark_dead
      end
    end
575276
def destroy(name):
    '''
    
    '''
    if not exists(name):
        raise ContainerNotExists("The container (%s) does not exist!" % name)
    cmd = ['lxc-destroy', '-f', '-n', name]
    subprocess.check_call(cmd)
160613
async def handle_student_job_closing(self, container_id, retval):
        
        try:
            self._logger.debug("Closing student %s", container_id)
            try:
                job_id, parent_container_id, socket_id, write_stream = self._student_containers_running[container_id]
                del self._student_containers_running[container_id]
            except asyncio.CancelledError:
                raise
            except:
                self._logger.warning("Student container %s that has finished(p1) was not launched by this agent", str(container_id), exc_info=True)
                return

            # Delete remaining student containers
            if job_id in self._student_containers_for_job:  # if it does not exists, then the parent container has closed
                self._student_containers_for_job[job_id].remove(container_id)

            killed = await self._timeout_watcher.was_killed(container_id)
            if container_id in self._containers_killed:
                killed = self._containers_killed[container_id]
                del self._containers_killed[container_id]

            if killed == "timeout":
                retval = 253
            elif killed == "overflow":
                retval = 252

            try:
                await self._write_to_container_stdin(write_stream, {"type": "run_student_retval", "retval": retval, "socket_id": socket_id})
            except asyncio.CancelledError:
                raise
            except:
                pass  # parent container closed

            # Do not forget to remove the container
            try:
                await self._docker.remove_container(container_id)
            except asyncio.CancelledError:
                raise
            except:
                pass  # ignore
        except asyncio.CancelledError:
            raise
        except:
            self._logger.exception("Exception in handle_student_job_closing")
400808
def stop(self, timeout=None):
        """"""
        logger.debug("docker plugin - Close thread for container {}".format(self._container.name))
        self._stopper.set()
1118477
def delete(self, container, del_objects=False):
        
        if del_objects:
            nms = self.list_object_names(container, full_listing=True)
            self.api.bulk_delete(container, nms, async_=False)
        uri = "/%s" % utils.get_name(container)
        resp, resp_body = self.api.method_delete(uri)
358279
def delete_container_2(self, name):
        
        code, container = self.get_container(name)
        if code == httplib.NOT_FOUND:
            return True
        elif code != httplib.OK:
            self.logger.error("Container %s on %s not exists. %d", name, self._host, code)
            return False

        if container.status.Running:
            code, message = self.change_container(name)
            if code != httplib.OK:
                self.logger.error("Stop container %s on %s error, status code %d, message %s", name, self._host, code,
                                  objson.dumps(message))
                return False

        code, message = self.delete_container(name)
        if code != httplib.OK:
            self.logger.error("Delete container %s on %s error, status code %d, message %s", name, self._host, code,
                              objson.dumps(message))
            return False
        return True
1102511
def killTask(self, driver, taskId):
        
        try:
            pid = self.runningTasks[taskId]
            pgid = os.getpgid(pid)
        except KeyError:
            pass
        else:
            os.killpg(pgid, signal.SIGKILL)
1090386
def remove_container(name, force=False):
    

    try:
        if not force:
            _get_docker().stop(name)
    except APIError:
        pass
    try:
        _get_docker().remove_container(name, force=True)
        return True
    except APIError:
        return False