capabilities.work

Stop and Remove a Container

A 4-step recipe with Docker. We can help you get access.

Recipe · 4 steps

Stop and Remove a Container

with Docker

Gracefully stop a container found by name and remove it once it has exited.

  1. List containers including stopped ones, filtered to the supplied name, so the flow resolves a concrete container id before acting on it.
  2. Send a graceful stop to the container. The daemon returns 204 when it stopped the container and 304 when it was already stopped, so both are acceptable outcomes for this step.
  3. Block until the container reaches the not-running condition and capture the exit code, so removal cannot race a still-shutting-down container.
  4. Remove the stopped container, optionally taking its anonymous volumes with it so the host is not left with orphaned data.
What you'll need to have ready
  • containerName: Name of the container to stop and remove.
  • stopTimeout: Seconds to wait for a graceful stop before the daemon kills the container.
  • removeVolumes: Remove anonymous volumes associated with the container.
For your developer

Arazzo workflow docker:stop-and-remove-container, 4 operations: ContainerList → ContainerStop → ContainerWait → ContainerDelete. Specs on APIs.io.