使用 Docker Compose 时如何修复 Blackfire 分析错误?

How to fix Blackfire profiling error when using with Docker Compose?

由于 docker-compose.yml 文件,我的应用程序在开发模式下以 Docker 运行。

我按照 Docker doc and the PHP Probe doc.

安装了 Blackfire

我的浏览器中安装了 Firefox 插件。

尝试分析我的页面 (http://localhost) 时出现以下错误:

Are You Authorized to Profile this Page? Probe Not Found or Invalid signature.

我按照 Troubleshooting 中的指示尝试修复错误:

为什么会出现此错误?我该如何解决?

在 docker-compose.yml 文件中有关 installing Blackfire with Docker 的文档中,ports 选项中给定的端口是 8307.

version: '3'
services:
  blackfire:
    image: blackfire/blackfire:2
    ports: ["8307"]
    environment:
        # Exposes BLACKFIRE_* environment variables from the host
        BLACKFIRE_SERVER_ID: ~
        BLACKFIRE_SERVER_TOKEN: ~
        BLACKFIRE_CLIENT_ID: ~
        BLACKFIRE_CLIENT_TOKEN: ~

在关于 enabling the PHP Probe with Docker 的文档中,Linux 映像和 Alpine 映像中的给定端口都是 8707(请参阅以 && printf "extension=blackfire.so 开头的倒数第二行)。下面的示例 Linux 图片:

FROM php:7.4-fpm

RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
    && architecture=$(case $(uname -m) in i386 | i686 | x86) echo "i386" ;; x86_64 | amd64) echo "amd64" ;; aarch64 | arm64 | armv8) echo "arm64" ;; *) echo "amd64" ;; esac) \
    && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/$architecture/$version \
    && mkdir -p /tmp/blackfire \
    && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
    && mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
    && printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
    && rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz

您应该更改一个或另一个端口,使其在两个地方具有相同的端口。然后重新启动容器。


编辑:错误已修复。