4

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"
Kern
  • 858
  • 1
  • 8
  • 24

2 Answers2

2

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

0

As you override the blackfire container name, you need to adapt the blackfire.agent_socket=tcp://blackfire:8707 parameters to match you container name (ie: blackfire.agent_socket=tcp://my_app_blackfire:8707).

  • I tried but it changed nothing, I have the same error and the same logs ! – Kern Dec 06 '16 at 13:40
  • 2
    Hum just spotted, your phpfpm container doesn't have any link to the blackfire container. – Tugdual Saunier Dec 06 '16 at 14:57
  • 1
    Wonderful ! I removed the link to NGINX and the volumes from Blackfire container, set the link from PHP-FPM to it, and it worked ! I just had to replace my_app_web with the NGINX container IP in the command line ! Thank you so much ! Post it as an answer and I will validate it :) ! – Kern Dec 06 '16 at 15:44
  • Great! I just posted it as an answer :) – Tugdual Saunier Dec 12 '16 at 13:30
  • @Kern So what's your change on `docker-compose.yml` ? Cause i face another problem where nor php nor nginx drop errors and blackfire doesn't seem to receive any request – Senorihl Oct 02 '17 at 14:23
  • @Senorihl Did you check Blackfire logs as well ? ```docker logs blackfire``` should output something. This is quiet far from me now, but perhaps I can help anyway :D ! – Kern Oct 02 '17 at 15:14
  • @Kern I only had init logs such as `blackfire_1 | [2017-10-03T07:41:58Z] DEBUG: New value of DefaultSpec.LastMaxAge: 24h0m0s`, `blackfire_1 | [2017-10-03T07:41:58Z] DEBUG: Listening for connections on 'tcp://0.0.0.0:8707'` and `blackfire_1 | [2017-10-03T07:41:58Z] DEBUG: Waiting for new connection` – Senorihl Oct 03 '17 at 07:43
  • @Kern it works perfectly when I run `blackfire curl http://my_php_container/` but when i use any web browser it should works as well right ? except it doesn't :-( – Senorihl Oct 03 '17 at 07:46
  • @Senorihl You want to use the companion ? I don't remember if I succeeeded to use it. Is your blackfire command in a dedicated container ? If so, are you sure you made the correct links between your containers ? With Docker Compose V3 you can use the networks to ease this – Kern Oct 04 '17 at 08:22