<@ULVA73B9P> does this setting exist as an env fla...
# ask-marvin
m
@Marvin does this setting exist as an env flag for prefect worker containers
PREFECT_DOCKER_AUTO_REMOVE: "true"
m
thought for 298.1 seconds
Short answer: No — there isn’t an env var
PREFECT_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:
Copy 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:
Copy code
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):
Copy code
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.