Martynas Urbanavičius
04/03/2026, 7:55 AMPREFECT_DOCKER_AUTO_REMOVE: "true"Marvin
04/03/2026, 7:55 AMMarvin
04/03/2026, 8:00 AMPREFECT_DOCKER_AUTO_REMOVE for Prefect workers.
If you’re using the Prefect 3.x Docker worker and you want the containers it launches for flow runs to be cleaned up automatically, set the Docker worker job variable auto_remove to true. You can do that in a few ways:
- In your deployment code:
from prefect import flow
@flow
def my_flow():
...
my_flow.deploy(
name="my-deployment",
work_pool_name="my-docker-pool",
job_variables={"auto_remove": True},
)
- In prefect.yaml:
deployments:
- name: my-deployment
entrypoint: flows.py:my_flow
work_pool:
name: my-docker-pool
job_variables:
auto_remove: true
- Per run via CLI (verified):
prefect deployment run <FLOW_NAME>/<DEPLOYMENT_NAME> --job-variable auto_remove=true
- As the default for a Docker work pool: edit the pool’s base job template in the UI to include auto_remove: true in the job configuration.
Notes:
- This setting applies to the job containers the Docker worker launches for flow runs. If you meant the worker container itself (the long‑running process), its lifecycle is managed outside Prefect (e.g., docker run --rm or your orchestrator).
Docs:
- Docker worker reference (includes auto_remove)
- Run flows in Docker containers
- Customize job variables
If you’re on Prefect 2.x, let me know and I can tailor the guidance.