在Docker环境中使用Blackfire容器配置我的应用程序

时间:2016-12-05 18:20:57

标签: php symfony docker docker-compose blackfire

今天我正在尝试将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中,我放了documentation instructions

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

编辑:触发profile命令后,我的PHP-FPM容器中有以下日志和我的NGINX app日志:

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"

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

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