<@ULVA73B9P> when deploying from python sdk i am n...
# ask-marvin
p
@Marvin when deploying from python sdk i am not getting logs for docker image build steps and other logs
m
thought for 512.0 seconds
Got it — when deploying from the Python SDK in Prefect 3.x, the Docker image build and other deployment steps are pretty quiet by default. There isn’t a flag on
.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.
Copy code
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)
.
Copy code
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.
Copy code
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.