13
10

More than 3 years have passed since last update.

docker上のphpコンテナでcomposer installしたら、メモリ不足で落ちた話

Last updated at Posted at 2020-06-01

はじめに

docker上でlaravelの開発していて、必要なライブラリをcomposerでインストールしようとしたら下記のエラーが出て詰まった、、、:sweat_smile:

エラーメッセージ

Using version ^4.3 for laravel/socialite
./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 4096 bytes) in phar:///usr/bin/composer.phar/src/Composer/DependencyResolver/Solver.php on line 223

原因調査

コンテナに入って、以下のコマンドを実行


$ php -r 'phpinfo();' | grep memory_limit

$ memory_limit => 128M => 128M

確かにデフォルトのphpのメモリが少ない、、、

ちなみに -r は <?php を略したもので、
コマンドライン上でphpのプログラムを実行するためのオプションです!

↓参照元 phpコマンドのオプション
https://www.php.net/manual/ja/features.commandline.options.php

対処方法

  • phpのコンテナのdockerファイルに以下を追加
php/Dockerfile
 COPY php.ini /usr/local/etc/php/ 
  • php.iniをdockerファイルのディレクトリに作成
php/php.ini
  memory_limit = -1

 -1は上限なしという意味

  • コンテナを再起動し中に入ってメモリを確認する
  $ php -r 'phpinfo();' | grep memory_limit           
  $ memory_limit => -1 => -1

 php.iniの設定に切り替わってる〜!
 ナイスですね〜〜〜:thumbsup:と全裸の監督から聞こえてきそうです!

結果

もう一度composer installしたら、、、

Package manifest generated successfully

無事インストールできました!マーベラス!

13
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
10