Liliya Angelova
10/16/2025, 3:04 PMprefect_docker.deployments.steps.build_docker_image to enforce no caching of the image layers?Marvin
10/16/2025, 3:04 PMNate
10/16/2025, 3:07 PMNate
10/16/2025, 3:07 PM--no-cacheMarvin
10/16/2025, 3:09 PMignore_cache parameter.
- Python example:
from prefect_docker.deployments.steps import build_docker_image
result = build_docker_image(
image_name="my-image",
tag="latest",
ignore_cache=True, # equivalent to --no-cache
)
- prefect.yaml example:
build:
- prefect_docker.deployments.steps.build_docker_image:
image_name: my-image
tag: latest
ignore_cache: true
Optional: if you also want to ensure the base image is refreshed, pass pull=True via `build_kwargs`:
build:
- prefect_docker.deployments.steps.build_docker_image:
image_name: my-image
tag: latest
ignore_cache: true
pull: true
Repo for the Prefect Docker collection: prefect-dockerLiliya Angelova
10/16/2025, 3:11 PMNate
10/16/2025, 3:14 PM--no-cache like nocache
build:
- prefect_docker.deployments.steps.build_docker_image:
image_name: my-image
tag: latest
nocache: trueNate
10/16/2025, 3:16 PMignore_cache is vague naming, but that cache refers to caching the entire image build across deployment steps in prefect deploy --allMarvin
10/16/2025, 3:16 PMNate
10/16/2025, 3:16 PMMarvin
10/16/2025, 3:20 PMprefect_docker.deployments.steps.build_docker_image, ignore_cache controls Prefect’s step-level caching across prefect deploy --all runs (i.e., whether the step result is reused), not Docker’s layer cache.
Answering your original intent (disable Docker layer cache):
- There isn’t a dedicated “no Docker cache” flag exposed by this step today.
- You can try passing a passthrough kwarg to the underlying build client:
- For Docker SDK (docker-py): nocache: true
- For python-on-whales: cache: false
- In prefect.yaml, that would look like:
build:
- prefect_docker.deployments.steps.build_docker_image:
image_name: my-image
tag: latest
# ignore_cache: true # only affects Prefect step cache; optional
nocache: true # try this (docker-py style)
pull: true # ensure base image is refreshed
- If nocache isn’t recognized in your environment, try:
build:
- prefect_docker.deployments.steps.build_docker_image:
image_name: my-image
tag: latest
cache: false # python-on-whales style
pull: true
Alternative cache-busting approach (works regardless of client):
- Add a build arg and reference it in a no-op Dockerfile step to invalidate cache:
# prefect.yaml
build:
- prefect_docker.deployments.steps.build_docker_image:
image_name: my-image
tag: latest
build_args:
CACHEBUST: "2025-10-16T12:34:56Z" # or inject a timestamp/env var in your CI
# Dockerfile
ARG CACHEBUST
RUN echo "Cache bust: $CACHEBUST"
If you’d like, I can open an enhancement issue to expose a first-class no_cache parameter on the step so this is unambiguous. Repo: prefect-docker (issues: prefect-docker/issues).
Does one of the passthrough options (nocache vs cache: false) work in your environment? If not, I can help troubleshoot which Docker client your deployment is using.Liliya Angelova
10/16/2025, 3:23 PMnocache: true ! Thanks again for the great support! prefect rocketNate
10/16/2025, 3:23 PM