<@ULVA73B9P> Is there an argument i can pass to `p...
# ask-marvin
l
@Marvin Is there an argument i can pass to
prefect_docker.deployments.steps.build_docker_image
to enforce no caching of the image layers?
m
thought for 269.4 seconds
n
yea you can pass thru all docker kwargs
so i guess that'd be
--no-cache
m
Yes. Use the
ignore_cache
parameter. - Python example:
Copy code
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:
Copy code
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`:
Copy code
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-docker
l
Both right, i just never know how to translate cli args to the deployment yaml 😅
n
i think here the docker python SDK spells
--no-cache
like
nocache
Copy code
build:
    - prefect_docker.deployments.steps.build_docker_image:
        image_name: my-image
        tag: latest
        nocache: true
👀 1
@Marvin is wrong here but its our (my) fault,
ignore_cache
is vague naming, but that cache refers to caching the entire image build across deployment steps in
prefect deploy --all
m
thought for 234.9 seconds
n
m
You’re right—thanks for calling that out. Apologies for the confusion on my side. Clarification: - In
prefect_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:
Copy code
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:
Copy code
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:
Copy code
# 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.
l
It works now with
nocache: true
! Thanks again for the great support! prefect rocket
n
catjam