stopContainer method

Future<void> stopContainer(
  1. String id, {
  2. int timeout = 10,
})

Stops a running container gracefully.

Sends a SIGTERM (or the image's configured stop signal) and waits up to timeout seconds before sending SIGKILL.

Parameters:

  • id — container ID or name.
  • timeout — grace period in seconds before force-kill. Default: 10.

Implementation

Future<void> stopContainer(String id, {int timeout = 10}) async {
  final resp = await _request(
    'POST',
    '/containers/$id/stop',
    queryParams: {'t': timeout.toString()},
  );
  if (resp.statusCode != 204 && resp.statusCode != 304) {
    _throwIfError(resp);
  }
}