Parvez Mohammed
10/17/2025, 12:23 PMMarvin
10/17/2025, 12:23 PMMarvin
10/17/2025, 12:32 PM.deploy() that streams Docker build logs.
Here are a few ways to see those logs:
Option A: Pass stream_progress_to via DockerImage
- If you’re providing a DockerImage to image=, you can pass through stream_progress_to=sys.stdout so the build output is streamed to your console.
- This works in current 3.x; if you’re on an older patch where it’s ignored, use Option B.
import sys
from prefect import flow, deploy
from prefect.docker import DockerImage
@flow
def my_flow():
...
image = DockerImage(
name="myrepo/myimage",
tag="latest",
dockerfile="Dockerfile",
# Stream Docker build output to your console
stream_progress_to=sys.stdout,
# Any other build kwargs (e.g., platform, buildargs)
platform="linux/amd64",
)
deploy(
my_flow.to_deployment(name="prod"),
work_pool_name="docker",
image=image,
build=True,
push=True,
)
Option B: Manually build with logs, then deploy without building
- Build the image yourself with prefect.utilities.dockerutils.build_image() and stream the logs, then pass the prebuilt tag to deploy(..., build=False).
import sys
from pathlib import Path
from prefect import flow, deploy
from prefect.utilities.dockerutils import build_image
@flow
def my_flow():
...
# Build with streamed logs
build_image(
context=Path("."),
dockerfile="Dockerfile",
tag="myrepo/myimage:latest",
stream_progress_to=sys.stdout,
)
# Deploy without building/pushing (already done)
deploy(
my_flow.to_deployment(name="prod"),
work_pool_name="docker",
image="myrepo/myimage:latest",
build=False,
push=False,
)
Option C: Use the CLI for more verbose step output
- If you’re okay using the CLI, prefect deploy typically prints step output (including shell steps and Docker steps defined in prefect.yaml) directly to the terminal.
prefect deploy --help
# Then from your project root, something like:
prefect deploy ./flows/my_flow.py:my_flow -n prod
Notes on “other logs”
- Increasing Prefect’s log level (e.g., PREFECT_LOGGING_ROOT_LEVEL=DEBUG) will increase Prefect runtime logs, but it will not force Docker build output to stream. Docker build logs are separate from Prefect’s logging system.
Helpful docs
- Deploy via Python: Deploy via Python
- Docker utils API (build_image): Docker utilities API
- Logging customization (general Prefect logs): Logging customization
If you can share:
- The code snippet you’re using to deploy (Python SDK path), and
- Your Prefect version (e.g., 3.1.x),
I can tailor the exact approach to your setup and confirm whether Option A will work as-is or if Option B is the safer route.