Python Probe with Docker
Python

To be able to use Blackfire, add the probe to your Docker PHP image. Here is an example of a Dockerfile based on the official Docker Python image:

1
2
3
FROM python:3.9-buster

RUN pip install --upgrade pip blackfire

Base image

This example targets official Python Docker images. If you are using a custom image, you probably need to adapt it.

Build your container as usual:

1
Loading...

Upgrading

To upgrade the Probe, rebuild your Python container and relaunch it (you might need to use the --no-cache option to force the download of the latest Probe version).

If you use docker compose, you can connect your Python container and the agent using the following snippet:

Loading...

When profiling command line scripts, the process is slightly different than for HTTP requests.

You execute blackfire run which in the end runs an embedded agent and wraps your Python script with the required environment variables. Therefore, in this configuration you do not need to (and cannot) use the blackfire/blackfire image.

Instead, you need to fetch and use the blackfire client binary inside your Python container.

Here is an example of a Dockerfile based on the official Docker Python image that retrieves the client at build time:

1
2
3
4
5
6
7
8
Loading...

Build your container as usual:

1
Loading...

By default, the Probe is quiet and does not produce logs. To debug issues, pass -e BLACKFIRE_LOG_LEVEL=4 to the docker run command, and tail the logs via Docker:

1
Loading...

To install the Blackfire Agent using Docker, please refer to the dedicated documentation page.