4

今天我正在尝试将 Blackfire 添加到我的 Docker 堆栈中!我遵循了专门用于 Docker 实现的 Blackfire 文档,容器设置正确,但我无法成功创建我的应用程序的第一个配置文件。

这是一个 Symfony 堆栈。我有一个 PHP-FPM 容器和一个用于启动命令的 CLI 容器。NGINX 容器是网络服务器。

我的docker-compose.yml文件如下:

---
cli:
    container_name: my_app_cli
    build: cli
    volumes:
        - "./volumes/apps:/srv/apps"
    stdin_open: true
    tty: true
    environment:
        - PHP_EXTRA_CONFIGURE_ARGS=--with-ldap
    links:
        - mysql:mysql
        - redis:redis
        - rabbitmq:rabbitmq
        - web:web
        - blackfire:blackfire

mysql:
    container_name: my_app_mysql
    build: mysql
    environment:
        - MYSQL_DATABASES=my_database
        - MYSQL_ROOT_PASSWORD=sgreat_password
        - MYSQL_HOST=localhost
        - MYSQL_PORT=33306
        - MYSQL_USER=guest
        - MYSQL_PASSWORD=password
        - MYSQL_LOYALTY_DATABASE=my_database
    ports:
        # MySQL
        - "33306:3306"
    volumes:
        # Mysql
        - "./volumes/mysql:/var/lib/mysql"

phpmyadmin:
    container_name: my_app_phpmyadmin
    image: nazarpc/phpmyadmin
    ports:
        # PHPMyAdmin HTTP
        - "8082:80"
    links:
        - mysql:mysql

phpfpm:
    container_name: my_app_phpfpm
    build: phpfpm
    ports:
        - "9000:9000"
    environment:
        - PHP_EXTRA_CONFIGURE_ARGS=--with-ldap
    links:
        - mysql:mysql
    volumes:
        - "./volumes/apps:/srv/apps"

blackfire:
    container_name: my_app_blackfire
    image: blackfire/blackfire
    environment:
        # Exposes the host BLACKFIRE_SERVER_ID and TOKEN environment variables.
        - BLACKFIRE_CLIENT_ID
        - BLACKFIRE_CLIENT_TOKEN
        - BLACKFIRE_SERVER_ID
        - BLACKFIRE_SERVER_TOKEN
    links:
        - web:web
    volumes:
        - "./volumes/apps:/srv/apps"
    ports:
        - "8707:8707"

rabbitmq:
    container_name: my_app_rabbitmq
    image: rabbitmq:3.5-management
    volumes:
        - /var/lib/rabbitmq
    environment:
        RABBITMQ_USER: guest
        RABBITMQ_PASSWORD: guest
    ports:
        # rabbitmq management
        - "8085:15672"

redis:
    container_name: my_app_redis
    image: redis
    environment:
        REDIS_PASSWORD: great_password
    volumes:
        - "./volumes/redis:/data"
    ports:
        - "32772:6379"

web:
    container_name: my_app_web
    build: nginx
    environment:
        NGINX_ENABLED_VHOST: www.my_app.local
    extra_hosts:
        - "www.my_app.local:127.0.0.1"
    links:
        - phpfpm
    volumes:
        - "./volumes/apps:/srv/apps"
        - "./volumes/html:/usr/share/nginx/html"
        - "./volumes/logs/nginx:/var/log/nginx"
    ports:
        - "80:80"
        - "443:443"

我的环境变量使用我的 Blackfire ID 正确设置。

我尝试使用以下命令行制作我的个人资料:

docker exec my_app_blackfire blackfire curl --proxy http://my_app_web:80 http://www.my_app.local/api/stores

结果是:

Are you authorized to profile this page? No probe response, missing PHP extension or invalid signature for relaying agent.

在 PHP-FPM 和 CLI Dockerfiles 中,我都放置了文档说明

RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
    && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$version \
    && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp \
    && mv /tmp/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

编辑:触发配置文件命令后,我的 PHP-FPM 容器和 NGINX 应用程序日志中有以下日志:

PHP-FPM

[06-Dec-2016 10:01:12] WARNING: [pool www] child 9 said into stderr: "NOTICE: PHP message: PHP Warning:  Unknown: php_network_getaddresses: getaddrinfo failed: Name or service not known in Unknown on line 0"
172.17.0.7 -  06/Dec/2016:10:00:46 +0000 "GET /app_dev.php" 301
[06-Dec-2016 10:01:19] WARNING: [pool www] child 12 said into stderr: "NOTICE: PHP message: PHP Warning:  Unknown: php_network_getaddresses: getaddrinfo failed: Name or service not known in Unknown on line 0"
172.17.0.7 -  06/Dec/2016:10:01:12 +0000 "GET /app_dev.php" 301

NGINX

2016/12/06 10:01:19 [error] 7#7: *3 FastCGI sent in stderr: "PHP message: PHP Warning:  Unknown: php_network_getaddresses: getaddrinfo failed: Name or service not known in Unknown on line 0" while reading response header from upstream, client: 172.17.0.8, server: www.my_app.local, request: "GET http://www.my_app.local/api/stores HTTP/1.1", upstream: "fastcgi://172.17.0.6:9000", host: "www.my_app.local"
2016/12/06 10:01:26 [error] 8#8: *5 FastCGI sent in stderr: "PHP message: PHP Warning:  Unknown: php_network_getaddresses: getaddrinfo failed: Name or service not known in Unknown on line 0" while reading response header from upstream, client: 172.17.0.8, server: www.my_app.local, request: "GET http://www.my_app.local/api/stores HTTP/1.1", upstream: "fastcgi://172.17.0.6:9000", host: "www.my_app.local"
4

2 回答 2

2

嗡嗡声刚刚发现,您的 php-fpm 容器没有任何指向 blackfire 容器的链接。

于 2016-12-12T13:29:44.233 回答
0

当您覆盖 blackfire 容器名称时,您需要调整blackfire.agent_socket=tcp://blackfire:8707参数以匹配您的容器名称(即:) blackfire.agent_socket=tcp://my_app_blackfire:8707

于 2016-12-06T12:10:20.827 回答