Run composer inside Docker container for Drupal 8.5 (with support for composer-patches)

Using composer for Drupal 8 is a great thing. And running composer inside a Docker container is even better. But the official composer image ships a version of the patch tool, that is not fully compatible to cweagans/composer-patches (see the related pull request).

Gambry was so nice and provided a customized Docker image with a "full version" of the patch tool. So that patches can been applied via composer.json to an Drupal installation. But with Drupal 8.5 it breaks again, if you want to install Drupal via composer. Because with 8.5.x the installation process requires the PHP GD library.

I have now created also an adjusted docker image for composer which is based on that from gambry: cbeier/composer

This ships the official composer image with a compatible version of patch and with php-gd.

You can run this container with:
docker run --rm --interactive --tty --volume $PWD:/app --user $(id -u):$(id -g) cbeier/composer install

Or you add it to your .bashrc/.zshrc/... file:

composer() {
  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):/app \
    cbeier/composer "[email protected]"
}

Alternatively, a bash script can be created (/usr/local/bin/composer):

#!/bin/bash

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):/app \
  cbeier/composer "[email protected]"

Then Composer can be used as normal in your terminal: $ composer install

English | 27. July 2018
Stored in
Filled under

Add new comment