When using Local Beach, the PHP environment in the container more often than not is not the same as on the host machine. This can be a problem for running Composer commands. A way around this is the use of our Composer containers.

These containers can be used to make use of Composer as easy as this:

$ composer74 update --dry-run
Loading composer repositories with package information
Updating dependencies
Lock file operations: 124 installs, 0 updates, 0 removals
  - Locking amphp/amp (v2.6.0)
  - Locking amphp/byte-stream (v1.8.1)
  … many more lines, potentially
  - Locking webmozart/assert (1.9.1)
  - Locking webmozart/path-util (2.3.0)
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 3 updates, 0 removals
  - Upgrading neos/flow-development-collection (dev-master 32fd147 => dev-master adac338)
  - Upgrading seld/phar-utils (1.1.1 => 1.1.2)
  - Upgrading neos/neos-development-collection (dev-master a45d346 => dev-master b4cc4ab)
29 package suggestions were added by new dependencies, use `composer suggest` to see details.
91 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

The PHP in the container matches the PHP used in Beach and Local Beach, so compatibility is ensured. And you do not need the matching PHP version on your host machine, but can simply use the needed container version.

Using docker run

Behind the scenes composer74 calls docker run and uses our Composer container based on PHP 7.4:

docker run \
        --interactive --rm --user $(id -u):$(id -g) \
        --volume /etc/passwd:/etc/passwd:ro \
        --volume /etc/group:/etc/group:ro \
        --volume $(pwd):/application:delegated \
        --volume $HOME/.composer/cache:/home/composer/cache:delegated \
        --volume $HOME/.composer/auth.json:/home/composer/auth.json \
        flownative/composer2:7.4 update --dry-run

Using shell aliases

Running Composer with docker run requires a number of options to be given. The following can be used to make this a lot easier. Add these (as needed) to your shell profile, e.g. to ~/.zshrc or ~/.bashrc:

composer74 () {
    tty=
    tty -s && tty=--tty
    docker run \
        $tty \
        --interactive \
        --rm \
        --user $(id -u):$(id -g) \
        --volume /etc/passwd:/etc/passwd:ro \
        --volume /etc/group:/etc/group:ro \
        --volume $(pwd):/application:delegated \
        --volume $HOME/.composer/cache:/home/composer/cache:delegated \
        --volume $HOME/.composer/auth.json:/home/composer/auth.json \
        flownative/composer2:7.4 "$@"
}

composer80 () {
    tty=
    tty -s && tty=--tty
    docker run \
        $tty \
        --interactive \
        --rm \
        --user $(id -u):$(id -g) \
        --volume /etc/passwd:/etc/passwd:ro \
        --volume /etc/group:/etc/group:ro \
        --volume $(pwd):/application:delegated \
        --volume $HOME/.composer/cache:/home/composer/cache:delegated \
        --volume $HOME/.composer/auth.json:/home/composer/auth.json \
        flownative/composer2:8.0 "$@"
}

composer81 () {
    tty=
    tty -s && tty=--tty
    docker run \
        $tty \
        --interactive \
        --rm \
        --user $(id -u):$(id -g) \
        --volume /etc/passwd:/etc/passwd:ro \
        --volume /etc/group:/etc/group:ro \
        --volume $(pwd):/application:delegated \
        --volume $HOME/.composer/cache:/home/composer/cache:delegated \
        --volume $HOME/.composer/auth.json:/home/composer/auth.json \
        flownative/composer2:8.1 "$@"
}