Building an XProf Docker Image

This document describes how to build a Docker image for XProf using the official release from PyPI.

Dockerfile

Create a file named Dockerfile with the following content:

FROMpython:3.11-slim
ARGXPROF_VERSION=2.21.0
ENVPYTHONUNBUFFERED=1
WORKDIR/app
RUNpipinstall--no-cache-dirxprof==${XPROF_VERSION}
EXPOSE8791 50051
ENTRYPOINT["xprof"]
CMD["--logdir=/app/logs","--port=8791"]

How to Build

  1. Save the content above as Dockerfile in an empty directory.
  2. Build the image using the following command:

    dockerbuild-txprof:2.21.0.
    

You can change the version by modifying the XPROF_VERSION argument in the Dockerfile or by passing --build-arg XPROF_VERSION=<version> to the docker build command.

How to Run

Run with Local Logs

Map your local log directory to /app/logs in the container.

dockerrun-p8791:8791\
-v/tmp/xprof_logs:/app/logs\
xprof:2.21.0

Run with GCS Logs

Mount your local gcloud credentials so xprof can authenticate with Google Cloud Storage.

dockerrun-p8791:8791\
-v~/.config/gcloud:/root/.config/gcloud\
xprof:2.21.0\
--logdir=gs://your-bucket-name/xprof_logs--port=8791

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年11月13日 UTC.