フリーランス 技術調査ブログ

フリーランス/エンジニア Ruby Python Nodejs Vuejs React Dockerなどの調査技術調査の備忘録

docker環境にてcomposer install時のメモリエラーの解消方法

はじめに

  • docker環境で動作しているcomposer install をするとメモリエラーが発生するので解決方法を下記に記述する
  • 仮にphpdocをインストールする例になります。

エラーの内容

  • composer install を実行するとAllowed memory size of xxxxxxx bytesとエラーと表示される
# composer require --dev phpdocumentor/phpdocumentor
Using version ^2.9 for phpdocumentor/phpdocumentor
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 528384 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Pool.php on line 230

Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory

対処方法①

  • dockerのメモリを増設する。下記のメモリやswap領域をPCの可能な範囲で上げておく f:id:PX-WING:20201113082424p:plain

対処方法②

  • 下記のようにmemery_limitの制限を外して実行する。
php -d memory_limit=-1 /usr/local/bin/composer require --dev phpdocumentor/phpdocumentor

実行結果

  • メモリエラーは解消できた。下記は違うエラーだ。
# php -d memory_limit=-1 /usr/local/bin/composer require --dev phpdocumentor/phpdocumentor
Using version ^2.9 for phpdocumentor/phpdocumentor
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install phpdocumentor/phpdocumentor v2.9.1
    - Conclusion: remove nikic/php-parser v3.1.1
    - Installation request for phpdocumentor/phpdocumentor ^2.9 -> satisfiable by phpdocumento
``