phpsymfonydockerdocker-composeblackfire

Profile my app with Blackfire container in Docker environment


Today I am trying to add Blackfire to my Docker stack ! I followed the Blackfire documentation dedicated to Docker implementation, the container is set correctly but I can't succeed to make a first profile of my application.

This is a Symfony stack. I have a PHP-FPM container, and a CLI container where I launch commands. A NGINX container is the webserver.

My docker-compose.yml file is the following :

---
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"

My environment variables are properly set with my Blackfire IDs.

I try to make my profile with the following command line :

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

The result is :

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

In both PHP-FPM and CLI Dockerfiles, I put the 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

EDIT: After triggering the profile command, I have the following logs in my PHP-FPM container and my NGINX app logs :

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"

Solution

  • Hum just spotted, your php-fpm container doesn't have any link to the blackfire container.