質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

composer

Composerとは、PHP5.3.2以上で使用可能なパッケージ管理ツールです。指定ディレクトリ内だけでパッケージ管理します。

Q&A

解決済

1回答

2618閲覧

【docker】composerで使用できるメモリの上限があげられない

hasshy

総合スコア102

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

composer

Composerとは、PHP5.3.2以上で使用可能なパッケージ管理ツールです。指定ディレクトリ内だけでパッケージ管理します。

0グッド

0クリップ

投稿2019/07/21 09:04

EC2のコンテナ上で展開しているPHPの環境があり、composerで構成しています。
composerを実行したところ、メモリ不足で実行できませんでした。

Loading composer repositories with package information Updating dependencies (including require-dev) mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory Fatal error: Out of memory (allocated 386723840) (tried to allocate 9210786 bytes) in phar:///usr/bin/composer.phar/src/Composer/Util/RemoteFilesystem.php on line 459

メモリの上限をあげる方法を色々試してみたのですが、解決できず何か他に変更する方法はないでしょうか?

サーバーの性能について

EC2のt2.microインスタンスを使っていますので、メモリは1GBです。

実際に使用できるメモリ容量は約1GB弱なので、容量が不足している可能性はないと思われます。

sh

1$ docker stats (dockerコンテナ)
MEM USAGELIMIT
8.277MiB983.7MiB

試した事

php.iniファイルの上限をあげる

phpの設定で上限を変えるために、docker-compose up時に追加するiniファイルにmemory_limit = 512Mにして立ち上げました。

ini

1[php] 2memory_limit = 512M

しかし、tried to allocate上限は変わりません。

実際にコンテナにexecで入り、phpinfo()から直接確認しましたが、設定自体は変わっている事を確認しました。

sh

1$ php -r 'phpinfo();' | grep memory_limit 2memory_limit => 512M => 512M

コマンドラインで実行した時だけ、メモリの制限上限を

phpとcomposerそれぞれのメモリリミットを変更して見ましたが、メモリが変わりません。

phpのリミットを変更

上限を解除するために、memory_limitオプションを追加した状態でビルドしてみました。

sh

1$ php -d memory_limit=-1 /usr/bin/composer install

composerのリミット変更

上限を解除するために、COMPOSER_MEMORY_LIMITオプションを追加した状態でビルドしてみました。

sh

1$ COMPOSER_MEMORY_LIMIT=-1 composer install

composer時のログ

リミット変更時に、変更があるかもしれないと思いcomposer install -vvvで見てみましたが、知識不足で原因を見つけることができませんでした。

sh

1$ php -d memory_limit=-1 /usr/bin/composer install -vvv 2Reading ./composer.json 3Loading config file ./composer.json 4Checked CA file /etc/ssl/certs/ca-certificates.crt: valid 5Executing command (/var/www): git branch --no-color --no-abbrev -v 6Executing command (/var/www): git describe --exact-match --tags 7Executing command (/var/www): git log --pretty="%H" -n1 HEAD 8Executing command (/var/www): hg branch 9Executing command (/var/www): fossil branch list 10Executing command (/var/www): fossil tag list 11Executing command (/var/www): svn info --xml 12Failed to initialize global composer: Composer could not find the config file: /root/.composer/composer.json 13To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section 14Running 1.8.6 (2019-06-11 15:03:05) with PHP 7.2.19 on Linux / 4.14.121-109.96.amzn2.x86_64 15Loading composer repositories with package information 16Downloading https://repo.packagist.org/packages.json 17Writing /root/.composer/cache/repo/https---repo.packagist.org/packages.json into cache 18Updating dependencies (including require-dev) 19Reading /root/.composer/cache/repo/https---repo.packagist.org/p-provider-2013.json from cache 20Reading /root/.composer/cache/repo/https---repo.packagist.org/p-provider-2014.json from cache 21Reading /root/.composer/cache/repo/https---repo.packagist.org/p-provider-2015.json from cache 22Reading /root/.composer/cache/repo/https---repo.packagist.org/p-provider-2016.json from cache 23Reading /root/.composer/cache/repo/https---repo.packagist.org/p-provider-2017.json from cache 24Reading /root/.composer/cache/repo/https---repo.packagist.org/p-provider-2018.json from cache 25Reading /root/.composer/cache/repo/https---repo.packagist.org/p-provider-2018-10.json from cache 26Downloading http://repo.packagist.org/p/provider-2019-01%243295bb914c7815748ee210203dca40edbf9bf1fa1e8bfa4788919c646f9cb2be.json 27Writing /root/.composer/cache/repo/https---repo.packagist.org/p-provider-2019-01.json into cache 28Downloading http://repo.packagist.org/p/provider-2019-04%2476814d375d8b753fc8a655956f4804ada8be962cebbbf8b665f5c4b7eb3e1a01.json 29Writing /root/.composer/cache/repo/https---repo.packagist.org/p-provider-2019-04.json into cache 30Downloading http://repo.packagist.org/p/provider-2019-07%24ce294b73ec16ae3655063841b37f82028db8da0f2d3d05069bc09e9d6d6b3a37.json 31Writing /root/.composer/cache/repo/https---repo.packagist.org/p-provider-2019-07.json into cache 32Reading /root/.composer/cache/repo/https---repo.packagist.org/p-provider-archived.json from cache 33Downloading http://repo.packagist.org/p/provider-latest%24788a051f4a9cd5933b41c98ae8788cf0613bd0b6b85f04df6170a65ee3261422.json 34Writing /root/.composer/cache/repo/https---repo.packagist.org/p-provider-latest.json into cache 35Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-laravel$laravel.json from cache 36Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-endroid$qr-code.json from cache 37Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-bacon$bacon-qr-code.json from cache 38Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-endroid$installer.json from cache 39Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-khanamiryan$qrcode-detector-decoder.json from cache 40Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-myclabs$php-enum.json from cache 41Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-symfony$http-foundation.json from cache 42Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-symfony$options-resolver.json from cache 43Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-symfony$property-access.json from cache 44Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-dasprid$enum.json from cache 45Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-symfony$polyfill-mbstring.json from cache 46Downloading http://repo.packagist.org/p/symfony/polyfill-php70%24206ebeb77d2e1d7d9466f2ac634b5f2f94523b17acc3b5cb22f194a0b5764259.json 47Writing /root/.composer/cache/repo/https---repo.packagist.org/provider-symfony$polyfill-php70.json into cache 48Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-symfony$mime.json from cache 49Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-symfony$inflector.json from cache 50Downloading http://repo.packagist.org/p/paragonie/random_compat%24ae8b0d2677b2b015ef3fcb7a1680c724e7c51d7bcc76c2ecd8405fb0ff597e92.json 51Writing /root/.composer/cache/repo/https---repo.packagist.org/provider-paragonie$random-compat.json into cache 52Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-symfony$polyfill-intl-idn.json from cache 53Downloading http://repo.packagist.org/p/symfony/polyfill-ctype%24f425dfc720a65a43b3815a48923ca568d1a9db63dfc6072224dab3a08b7382fe.json 54Writing /root/.composer/cache/repo/https---repo.packagist.org/provider-symfony$polyfill-ctype.json into cache 55Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-symfony$polyfill-php72.json from cache 56Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-fideloper$proxy.json from cache 57Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-illuminate$contracts.json from cache 58Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-psr$container.json from cache 59Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-psr$simple-cache.json from cache 60Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-guzzlehttp$guzzle.json from cache 61Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-guzzlehttp$psr7.json from cache 62Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-guzzlehttp$promises.json from cache 63Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-psr$http-message.json from cache 64Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-ralouphie$getallheaders.json from cache 65Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-kris$laravel-form-builder.json from cache 66Downloading http://repo.packagist.org/p/laravelcollective/html%24e21fab862745fb1b95dd8f0814b8ff144ff12101517540d13c9c5198991c7dd1.json 67Writing /root/.composer/cache/repo/https---repo.packagist.org/provider-laravelcollective$html.json into cache 68Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-illuminate$database.json from cache 69Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-illuminate$validation.json from cache 70Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-illuminate$http.json from cache 71Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-illuminate$routing.json from cache 72Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-illuminate$session.json from cache 73Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-illuminate$support.json from cache 74Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-illuminate$view.json from cache 75Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-illuminate$container.json from cache 76Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-nesbot$carbon.json from cache 77Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-symfony$translation.json from cache 78Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-illuminate$translation.json from cache 79Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-egulias$email-validator.json from cache 80Reading /root/.composer/cache/repo/https---repo.packagist.org/provider-symfony$http-kernel.json from cache 81Downloading http://repo.packagist.org/p/illuminate/pipeline%24f4a2e4383e9a0e0c0e02c0289dbc90405bfbe7a47a58d18c042e266858305c0c.json 82 83mmap() failed: [12] Cannot allocate memory 84 85mmap() failed: [12] Cannot allocate memory 86 87Fatal error: Out of memory (allocated 386723840) (tried to allocate 9210786 bytes) in phar:///usr/bin/composer.phar/src/Composer/Util/RemoteFilesystem.php on line 459

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

実際に使用できるメモリ容量は約1GB弱なので、容量が不足している可能性はないと思われます。

これの根拠は、freeコマンドの結果でしょうか。
docker以外にも立ち上がっているプロセスがあれば、より少ない可能性があります。
(composerが400MB使用しているので)

また、swapは作成されていますか?

投稿2019/07/24 07:03

mikkame

総合スコア5036

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hasshy

2019/07/24 07:51 編集

何時もご助言いただきありがとうございます。 > これの根拠は、freeコマンドの結果でしょうか。 いえ、docker statsの結果です。 コンテナ機動で使っているメモリと、上限を見るために実行した結果を記述しました。 ただ、ご助言を参考に解決できました。 どうやら、自分が忘れていたmysqldが動いており、それが500MB近くメモリを使っていました。 composerので使うメモリが確保できなかった様です。 freeで確認すると、100MB強しか余っていませんでした。 mysqldを止めたところ解決できました。 ご助言いただきありあとうございます。
mikkame

2019/07/24 07:51

swap作った方がいいですよ(仮想メモリ)
hasshy

2019/07/24 07:58

ご助言いただきありがとうございます。 お恥ずかしながら、swapについて今情報を集めさせていただきました。 確かに、今回の様にメモリ使い切る事を想定してあらかじめswap領域を用意した方が良さそうですね。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問