NewRelicのアカウントを作成し、言われるままにPHPのAgentを設定しているとエラーに遭遇。どうやらnewrelic.iniがコンテナ内に存在しておらずsedコマンドが実行できないとのこと。
$ docker build -t "php:8.3.7-apache_with_newrelic" --build-arg NEW_RELIC_AGENT_VERSION=10.10.0.1 --build-arg NEW_RELIC_LICENSE_KEY=<NEW_RELIC_LICENSE_KEY> --build-arg NEW_RELIC_APPNAME="app" --build-arg IMAGE_NAME="php:8.3.7-apache" .
=> ERROR [3/3] RUN sed -i -e "s/newrelic.license[[:space:]]*=[[:space:]]*.*/newrelic.license = d167359567f19fa8ba00506550447e32FFFFNRAL/" -e "s/newrelic.appname 0.1s
------
> [3/3] RUN sed -i -e "s/newrelic.license[[:space:]]*=[[:space:]]*.*/newrelic.license = d167359567f19fa8ba00506550447e32FFFFNRAL/" -e "s/newrelic.appname[[:space:]]*=[[:space:]]*.*/newrelic.appname = app/" -e "$a newrelic.daemon.address=newrelic-php-daemon:31339" /usr/local/etc/php/conf.d/newrelic.ini:
0.118 sed: can't read /usr/local/etc/php/conf.d/newrelic.ini: No such file or directory
------
2 warnings found (use docker --debug to expand):
- InvalidDefaultArgInFrom: Default value for ARG ${IMAGE_NAME} results in empty or invalid base image name (line 2)
- SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "NEW_RELIC_LICENSE_KEY") (line 5)
Dockerfile:14
--------------------
13 |
14 | >>> RUN sed -i \
15 | >>> -e "s/newrelic.license[[:space:]]*=[[:space:]]*.*/newrelic.license = ${NEW_RELIC_LICENSE_KEY}/" \
16 | >>> -e "s/newrelic.appname[[:space:]]*=[[:space:]]*.*/newrelic.appname = ${NEW_RELIC_APPNAME}/" \
17 | >>> -e "\$a newrelic.daemon.address=newrelic-php-daemon:31339" \
18 | >>> /usr/local/etc/php/conf.d/newrelic.ini
19 |
--------------------
ERROR: failed to solve: process "/bin/sh -c sed -i -e \"s/newrelic.license[[:space:]]*=[[:space:]]*.*/newrelic.license = ${NEW_RELIC_LICENSE_KEY}/\" -e \"s/newrelic.appname[[:space:]]*=[[:space:]]*.*/newrelic.appname = ${NEW_RELIC_APPNAME}/\" -e \"\\$a newrelic.daemon.address=newrelic-php-daemon:31339\" /usr/local/etc/php/conf.d/newrelic.ini" did not complete successfully: exit code: 2
View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/qeozjg51qn4jmbnbiuyilxmb7
sedコマンドを実行せずビルドし、コンテナの中で確認するとファイルがない。なぜだろうと悩みました。
PHP AgentのバージョンとPHPのバージョンの関連性
フォーラムに答えがありました。
I am not sure of the steps followed by you to instal the PHP agent via docker. However I would recommend checking out the Docker and other container environments: Install PHP agent doc, however before doing so, its vital to ensure all the PHP agent compatibility and requirements are met.
要約) Dockerやその他のコンテナ周りの環境、またはPHPエージェントの互換性等を確認することをおすすめします。
https://forum.newrelic.com/s/hubtopic/aAXPh0000002UI9OAM/php-agent-installation-issues
どうやらPHP AgentのバージョンとPHPのバージョンには対応があるよう。
phpのコンテナイメージは何でも良いと思ってた...
ということで以下のリンクから対応を確認すると、自分が利用していたPHP8.3.7はAgentのバージョンが10.15.0.4よりも高い必要がある様子。そのため指示通りに進めるとAgentのバージョンが10.10.0.1になるため上手く行かなかったのか。
最新バージョンとアーカイブ
最新バージョンとアーカイブは以下のリンクから確認できます。対応したバージョンを利用してみてください。
ということで以下のようにコマンドを修正し、再度実行すると問題なく実行できました~ めでたしめでたし
--build-arg NEW_RELIC_AGENT_VERSION=11.3.0.16
おまけ
以下のようにcurlを用いて常に最新のバージョンを取得する方法を利用されている方もいました。
$ echo NEW_RELIC_AGENT_VERSION=$(curl -s https://download.newrelic.com/php_agent/release/ | grep -o '[1-9][0-9]\?\(\.[0-9]\+\)\{3\}' | head -n1)
NEW_RELIC_AGENT_VERSION=11.3.0.16