Skip to content

Run Composer in the container

$ grim composer require league/csv

A project needs a PHP library that is not a module: a CSV reader, an SDK, a dev tool. Installing it with the Composer on your machine resolves it against your machine's PHP and extensions, not the app's. grim composer runs Composer in the app container, so what it resolves is what the app can load.

It is for plain PHP packages. Modules and themes are not Composer's business: grim require adds them and grim update moves them.

Usage

$ grim composer require league/csv            # add a library
$ grim composer -- require phpunit/phpunit --dev
$ grim composer dump-autoload                 # rebuild the autoloader
$ grim composer -- show --outdated            # options go after a double dash

Run it from the project directory, with the stack up.

Arguments and options

Run composer command in app container

Usage

grim composer [<cmd>...]

Arguments

Argument Description
cmd Composer command and arguments (optional, repeatable)

What it actually does

It runs docker compose exec app composer followed by what you typed, with your terminal attached, so Composer can ask its questions. Output and exit code are Composer's own. composer.json, composer.lock and vendor/ change in the project directory, because it is mounted into the container.

Pitfalls

An option without -- never reaches Composer

grim reads the command line first. An option it does not know, such as --dev, is dropped without a word, together with everything typed after it. grim composer require phpunit/phpunit --dev installs the package as a regular dependency. Put a double dash first: grim composer -- require phpunit/phpunit --dev.

The stack has to be up

The command enters a running container. service "app" is not running means there is none; run grim up. On a fresh clone that same grim up installs the dependencies by itself, so there is no need to run install by hand.

After it finishes

Commit composer.json and composer.lock together. Colleagues get the package with their next grim composer install.