LoginSignup
2
1

More than 3 years have passed since last update.

【Laravel】composer require時のメモリ不足エラーの対処法【Docker】

Last updated at Posted at 2020-10-26

概要

Docker環境でcomposerインストール時に表題のエラーが発生しました。
ググっていくつかの方法を試しましたが解決に至るまで少し時間を要したので備忘として残しておきます。

環境

Docker:19.03.8
Laravel:6.19.1

エラー内容

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

メモリ不足でインストールできないよ〜というエラーです。

解決方法

1.以下を実行しappコンテナに入る

docker-compose exec app bash

2.以下でインストール

php -d memory_limit=-1 /usr/bin/composer require インストールしたいライブラリ名(ex: fruitcake/laravel-cors)

-dはdefineの略で、php.iniで指定できる設定値を明示的に設定できるようです。
PHPコマンドラインオプション

このオプションにより php.ini で指定できる設定ディレクティブに カスタム値を設定することができます。構文は以下のようになります。
-d configuration_directive[=value]

-d memory_limit=-1とすることで、メモリlimitを無制限でコマンドを実行することができます。

2
1
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
2
1