代码之家  ›  专栏  ›  技术社区  ›  kamal

使用blackfire的基于Docker的php应用程序评测

  •  3
  • kamal  · 技术社区  · 6 年前

    我使用的是一个简单的基于Docker的PHP应用程序( https://github.com/fuhrysteve/php-docker-apache-example.git

    1.安装BlackFire的Chrome扩展(在Chrome上)

    2.定义这些环境变量:

    $export BLACKFIRE_CLIENT_ID=921b5dfa-a9e0-4979-8bd1-a7a7a2acf031
    $export BLACKFIRE_CLIENT_TOKEN=af050bfc9cf3761082828e3f5e4f31ada89649f0635c0cb445c86f26f72a8e18
    $export BLACKFIRE_SERVER_ID=3534d1d9-7c0b-4c5b-9aad-eda497b27494
    $export BLACKFIRE_SERVER_TOKEN=79082e6b82122630d6be03bb8f3f8c9544fadada78156ef4606d86f639644eb0
    

    3.安装代理

    docker run --name="blackfire" -d -e BLACKFIRE_SERVER_ID -e BLACKFIRE_SERVER_TOKEN blackfire/blackfire
    

    4.启用PHP探测
    $cat Dockerfile

    FROM php:7.0-apache
    
    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 \
    && 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://myapp:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
    && rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
    
    
    RUN apt-get update && \
    #apt-get install -y php5-mysql && \
    apt-get clean
    
    COPY myapp /var/www/html/
    

    5.构建myapp容器
    $docker build -t php-docker-apache-example .

    6.Docker跑步

    $docker network create myphp
    
    $docker run -d -p 8080:80 --net=myphp-app -v `pwd`:/var/www/html php-blackfire
    

    结果:

    Unable to find image 'php-blackfire:latest' locally
    docker: Error response from daemon: pull access denied for php-blackfire, repository does not exist or may require 'docker login'.
    See 'docker run --help'.
    

    $ docker login 登录成功

    $ docker run -d -p 8080:80 --net=myphp-app -v \ 黑火`

    docker:来自守护程序的错误响应:php blackfire的拉取访问被拒绝,存储库不存在或可能需要“docker登录”。
    请参阅“docker run--帮助”。
    

    然后我试图找到黑火 本地映像

    $docker images | grep black
    blackfire/blackfire         latest              fe5c5468b23d        7 days ago          25.7MB
    $ docker run -d -p 8080:80 --net=myphp -v pwd:/var/www/html blackfire/blackfire
    26005945907dd55d55d174444dcf53ef176e5b45d0086309496122d0b02e3918
    $ docker ps
    CONTAINER ID        IMAGE                 COMMAND             CREATED             STATUS              PORTS               NAMES
    7768e1266e81        blackfire/blackfire   "blackfire-agent"   38 minutes ago      Up 38 minutes       8707/tcp            blackfire
    

    7.在容器中运行php应用程序

    $docker run -d -p 8080:80 php-docker-apache-example

    $docker ps

    CONTAINER ID        IMAGE                       COMMAND                  CREATED              STATUS              PORTS                  NAMES
    6dd287bfbb44        php-docker-apache-example   "docker-php-entrypoi…"   About a minute ago   Up About a minute   0.0.0.0:8080->80/tcp   determined_snyder
    7768e1266e81        blackfire/blackfire         "blackfire-agent"        44 minutes ago       Up 44 minutes       8707/tcp               blackfire
    

    8.浏览 http://localhost:8080/

    9.在Chrome中运行探查器

    错误:

    您有权配置此页面吗?未找到探测,签名无效(HTTP 200)。故障排除?

    docker日志不显示相关错误:

    $docker logs 6dd287bfbb44 -f
    AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
    AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
    [Mon Dec 10 22:24:13.490536 2018] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.0.32 configured -- resuming normal operations
    [Mon Dec 10 22:24:13.490688 2018] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
    172.17.0.1 - - [10/Dec/2018:22:25:50 +0000] "GET / HTTP/1.1" 200 407 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"
    
    0 回复  |  直到 6 年前