How to stop and remove a Docker container

Stopping a Docker container ends the running process, while removing the container deletes the stopped container record. Keeping those actions separate prevents accidental removal of a container that still needs logs, exit status, or filesystem inspection.

docker stop sends the configured stop signal and waits before forcing the process to exit. docker rm removes only a stopped container unless --force is used, and it does not delete named volumes by default.

Check whether the container owns data before removal. If the workload uses bind mounts or named volumes, removing the container leaves that storage behind, but deleting anonymous volumes or pruning later can still remove data that another recovery step expected.

Steps to stop and remove a Docker container:

  1. Identify the container name and current state.
    $ docker ps --all --filter name=app-worker
    CONTAINER ID   IMAGE                                  COMMAND     CREATED       STATUS       PORTS     NAMES
    8e0de02db6f2   registry.example.com/team/worker:1.0   "worker"    3 hours ago   Up 3 hours             app-worker
  2. Stop the running container.
    $ docker stop app-worker
    app-worker

    Add --timeout when the application needs a longer graceful shutdown window.

  3. Confirm that the container is stopped before removing it.
    $ docker ps --all --filter name=app-worker
    CONTAINER ID   IMAGE                                  COMMAND     CREATED       STATUS                     PORTS     NAMES
    8e0de02db6f2   registry.example.com/team/worker:1.0   "worker"    3 hours ago   Exited (0) 4 seconds ago             app-worker
  4. Remove the stopped container.
    $ docker rm app-worker
    app-worker

    Do not add --volumes unless anonymous volumes attached to this container should be deleted too.

  5. Verify that the container record no longer exists.
    $ docker ps --all --filter name=app-worker
    CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES