Thomas DeBroux
03/13/2026, 3:22 AMMarvin
03/13/2026, 3:22 AMMarvin
03/13/2026, 3:25 AMauto_remove job variable to true (this is equivalent to docker run --rm). By default it’s false, so containers stick around after the flow exits.
Ways to enable it:
- Per deployment (job variables)
- Python deploy:
from prefect import flow
@flow
def my_flow():
...
if __name__ == "__main__":
my_flow.deploy(
name="auto-cleanup",
work_pool_name="my-docker-pool",
job_variables={"auto_remove": True},
)
- prefect.yaml:
deployments:
- name: auto-cleanup
work_pool:
name: my-docker-pool
job_variables:
auto_remove: true
- Default for a Docker work pool (base job template)
- In the UI: Work Pools -> your Docker pool -> Edit base job template -> set the variables.auto_remove.default to true and ensure job_configuration.auto_remove is wired to {{ auto_remove }}.
- Or via CLI, inspect the current template:
prefect work-pool inspect my-docker-pool -o json
Then update the pool with a modified base job template.
Notes and caveats:
- This only removes the container; images, networks, and volumes are not pruned by Prefect.
- With auto_remove: true, Docker deletes the container as soon as it exits. If you rely on inspecting containers after failure, leave it false.
- If you still see leftover containers after enabling auto_remove, check whether a deployment-level job_variables is overriding the pool default.
Want me to help you update your pool template or deployment config? Also, are you on Prefect 3.x and are the leftovers strictly containers (not volumes/images)?