2

I am trying to build a docker image with a PHP application in it.

This application installs some dependencies via composer.json and, after composer install, needs some customizations done (eg some files must be copied from vendor folder into other locations and so on).

So I have written these steps as bash commands and putted in the composer.json post-install-cmd section.

This is my composer.json (I've omitted details, but the structure is the same):

{
  "name": "MyApp",
  "description": "My Service",
  "type": "project",
  "repositories": {
    "a-fancy-library-i-depend-on": {
      "type": "package",
      "package": {
        "name": "a-fancy-library-i-depend-on",
        "version": "1.0",
        "source": {
          "url": "https://github.com/a-fancy-library-i-depend-on",
          "type": "git",
          "reference": "master"
        }
      }
    },
  },
  "require": {
    "symfony/filesystem": "5.2.6",
    "symfony/yaml": "^4.2"
  },
  "require-dev": {
    "a-fancy-library-i-depend-on": "*"
  },
  "scripts": {
    "post-install-cmd": [
      "rm -rf ./src/setup",
      "cp -r vendor/a-fancy-library-i-depend-on/setup/ ./src/setup",
      "mkdir vendor/a-fancy-library-i-depend-on/log"
    ]
  },
  "autoload": {
    "classmap": [
      "src/"
    ]
  },
  "config": {
    "allow-plugins": {
      "a-fancy-library-i-depend-on/composer-module-installer": true
    }
  }
}

In my Dockerfile I have included a step for running composer install:

FROM php:7.4.20-fpm

RUN apt-get update && apt-get install -y git zlib1g-dev libzip-dev libpng-dev libicu-dev g++ zip unzip

RUN docker-php-ext-install zip gd intl

RUN docker-php-ext-configure intl

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

ADD code /code

WORKDIR /code

RUN composer install

The problem is that the "after-install" scripts are NOT executed.

The image builds successfully, but the setup folder is empty.

If I run a container from this image and enter a bash on it

 docker container run -ti my-image:local bash

and then I try to run

# composer install

voilà! scripts are executed.

this is the composer install phase output of the build image command:

Step 10/15 : RUN composer install
 ---> Running in af5ffb3ef4e9
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Updating dependencies
Lock file operations: 76 installs, 0 updates, 0 removals
  - Locking gettext/gettext (v4.8.6)
  - Locking gettext/languages (2.9.0)
  - Locking phpfastcache/riak-client (3.4.3)
  - Locking phpmailer/phpmailer (v6.5.3)
  - Locking psr/cache (1.0.1)
  - Locking psr/container (1.1.2)
  - Locking psr/event-dispatcher (1.0.0)
  - Locking psr/log (1.1.4)
  - Locking robrichards/xmlseclibs (3.1.1)
  - Locking simplesamlphp/assert (v0.0.13)
  - Locking simplesamlphp/composer-module-installer (v1.1.8)
  - Locking simplesamlphp/saml2 (v4.4.0)
  - Locking simplesamlphp/simplesamlphp (v1.19.4)
  - Locking simplesamlphp/simplesamlphp-module-adfs (v0.9.9)
  - Locking simplesamlphp/simplesamlphp-module-authcrypt (v0.9.4)
  - Locking simplesamlphp/simplesamlphp-module-authfacebook (v0.9.3)
  - Locking simplesamlphp/simplesamlphp-module-authorize (v0.9.4)
  - Locking simplesamlphp/simplesamlphp-module-authtwitter (v0.9.3)
  - Locking simplesamlphp/simplesamlphp-module-authwindowslive (v0.9.1)
  - Locking simplesamlphp/simplesamlphp-module-authx509 (v0.9.9)
  - Locking simplesamlphp/simplesamlphp-module-authyubikey (v0.9.3)
  - Locking simplesamlphp/simplesamlphp-module-cas (v0.9.1)
  - Locking simplesamlphp/simplesamlphp-module-cdc (v0.9.2)
  - Locking simplesamlphp/simplesamlphp-module-consent (v0.9.8)
  - Locking simplesamlphp/simplesamlphp-module-consentadmin (v0.9.2)
  - Locking simplesamlphp/simplesamlphp-module-discopower (v0.10.1)
  - Locking simplesamlphp/simplesamlphp-module-exampleattributeserver (v1.0.0)
  - Locking simplesamlphp/simplesamlphp-module-expirycheck (v0.9.4)
  - Locking simplesamlphp/simplesamlphp-module-ldap (v0.9.17)
  - Locking simplesamlphp/simplesamlphp-module-memcachemonitor (v0.9.3)
  - Locking simplesamlphp/simplesamlphp-module-memcookie (v1.2.2)
  - Locking simplesamlphp/simplesamlphp-module-metarefresh (v0.9.7)
  - Locking simplesamlphp/simplesamlphp-module-negotiate (v0.9.12)
  - Locking simplesamlphp/simplesamlphp-module-oauth (v0.9.3)
  - Locking simplesamlphp/simplesamlphp-module-preprodwarning (v0.9.3)
  - Locking simplesamlphp/simplesamlphp-module-radius (v0.9.4)
  - Locking simplesamlphp/simplesamlphp-module-riak (v0.9.1)
  - Locking simplesamlphp/simplesamlphp-module-sanitycheck (v0.9.1)
  - Locking simplesamlphp/simplesamlphp-module-smartattributes (v0.9.2)
  - Locking simplesamlphp/simplesamlphp-module-sqlauth (v0.9.4)
  - Locking simplesamlphp/simplesamlphp-module-statistics (v0.9.6)
  - Locking simplesamlphp/twig-configurable-i18n (v2.3.4)
  - Locking symfony/cache (v5.4.2)
  - Locking symfony/cache-contracts (v2.5.0)
  - Locking symfony/config (v5.4.2)
  - Locking symfony/console (v5.4.2)
  - Locking symfony/dependency-injection (v5.4.2)
  - Locking symfony/deprecation-contracts (v2.5.0)
  - Locking symfony/error-handler (v5.4.2)
  - Locking symfony/event-dispatcher (v5.4.0)
  - Locking symfony/event-dispatcher-contracts (v2.5.0)
  - Locking symfony/filesystem (v5.2.6)
  - Locking symfony/finder (v5.4.2)
  - Locking symfony/framework-bundle (v5.4.2)
  - Locking symfony/http-foundation (v5.4.2)
  - Locking symfony/http-kernel (v5.4.2)
  - Locking symfony/polyfill-ctype (v1.24.0)
  - Locking symfony/polyfill-intl-grapheme (v1.24.0)
  - Locking symfony/polyfill-intl-normalizer (v1.24.0)
  - Locking symfony/polyfill-mbstring (v1.24.0)
  - Locking symfony/polyfill-php72 (v1.24.0)
  - Locking symfony/polyfill-php73 (v1.24.0)
  - Locking symfony/polyfill-php80 (v1.24.0)
  - Locking symfony/polyfill-php81 (v1.24.0)
  - Locking symfony/routing (v5.4.0)
  - Locking symfony/service-contracts (v2.5.0)
  - Locking symfony/string (v5.4.2)
  - Locking symfony/var-dumper (v5.4.2)
  - Locking symfony/var-exporter (v5.4.2)
  - Locking symfony/yaml (v4.4.36)
  - Locking twig/extensions (v1.5.4)
  - Locking twig/twig (v2.14.10)
  - Locking webmozart/assert (1.10.0)
  - Locking whitehat101/apr1-md5 (v1.0.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 76 installs, 0 updates, 0 removals
  - Downloading symfony/polyfill-php72 (v1.24.0)
  - Downloading symfony/polyfill-mbstring (v1.24.0)
  - Downloading symfony/polyfill-ctype (v1.24.0)
  - Downloading twig/twig (v2.14.10)
  - Downloading symfony/yaml (v4.4.36)
  - Downloading symfony/polyfill-php80 (v1.24.0)
  - Downloading symfony/var-exporter (v5.4.2)
  - Downloading symfony/deprecation-contracts (v2.5.0)
  - Downloading symfony/routing (v5.4.0)
  - Downloading symfony/polyfill-php73 (v1.24.0)
  - Downloading symfony/http-foundation (v5.4.2)
  - Downloading psr/event-dispatcher (1.0.0)
  - Downloading symfony/event-dispatcher-contracts (v2.5.0)
  - Downloading symfony/event-dispatcher (v5.4.0)
  - Downloading symfony/var-dumper (v5.4.2)
  - Downloading psr/log (1.1.4)
  - Downloading symfony/error-handler (v5.4.2)
  - Downloading symfony/http-kernel (v5.4.2)
  - Downloading symfony/polyfill-php81 (v1.24.0)
  - Downloading symfony/finder (v5.4.2)
  - Downloading symfony/filesystem (v5.2.6)
  - Downloading psr/container (1.1.2)
  - Downloading symfony/service-contracts (v2.5.0)
  - Downloading symfony/dependency-injection (v5.4.2)
  - Downloading symfony/config (v5.4.2)
  - Downloading psr/cache (1.0.1)
  - Downloading symfony/cache-contracts (v2.5.0)
  - Downloading symfony/cache (v5.4.2)
  - Downloading symfony/framework-bundle (v5.4.2)
  - Downloading symfony/polyfill-intl-normalizer (v1.24.0)
  - Downloading symfony/polyfill-intl-grapheme (v1.24.0)
  - Downloading symfony/string (v5.4.2)
  - Downloading symfony/console (v5.4.2)
  - Downloading twig/extensions (v1.5.4)
  - Downloading simplesamlphp/twig-configurable-i18n (v2.3.4)
  - Downloading simplesamlphp/simplesamlphp (v1.19.4)
  - Downloading simplesamlphp/composer-module-installer (v1.1.8)
  - Downloading gettext/languages (2.9.0)
  - Downloading webmozart/assert (1.10.0)
  - Downloading simplesamlphp/simplesamlphp-module-statistics (v0.9.6)
  - Downloading simplesamlphp/simplesamlphp-module-sqlauth (v0.9.4)
  - Downloading simplesamlphp/simplesamlphp-module-smartattributes (v0.9.2)
  - Downloading simplesamlphp/simplesamlphp-module-sanitycheck (v0.9.1)
  - Downloading phpfastcache/riak-client (3.4.3)
  - Downloading simplesamlphp/simplesamlphp-module-riak (v0.9.1)
  - Downloading simplesamlphp/simplesamlphp-module-radius (v0.9.4)
  - Downloading simplesamlphp/simplesamlphp-module-preprodwarning (v0.9.3)
  - Downloading simplesamlphp/simplesamlphp-module-oauth (v0.9.3)
  - Downloading simplesamlphp/simplesamlphp-module-ldap (v0.9.17)
  - Downloading simplesamlphp/simplesamlphp-module-negotiate (v0.9.12)
  - Downloading simplesamlphp/simplesamlphp-module-metarefresh (v0.9.7)
  - Downloading simplesamlphp/simplesamlphp-module-memcookie (v1.2.2)
  - Downloading simplesamlphp/simplesamlphp-module-memcachemonitor (v0.9.3)
  - Downloading simplesamlphp/simplesamlphp-module-expirycheck (v0.9.4)
  - Downloading simplesamlphp/simplesamlphp-module-exampleattributeserver (v1.0.0)
  - Downloading simplesamlphp/simplesamlphp-module-discopower (v0.10.1)
  - Downloading simplesamlphp/simplesamlphp-module-consent (v0.9.8)
  - Downloading simplesamlphp/simplesamlphp-module-consentadmin (v0.9.2)
  - Downloading simplesamlphp/simplesamlphp-module-cdc (v0.9.2)
  - Downloading simplesamlphp/simplesamlphp-module-cas (v0.9.1)
  - Downloading simplesamlphp/simplesamlphp-module-authyubikey (v0.9.3)
  - Downloading simplesamlphp/simplesamlphp-module-authx509 (v0.9.9)
  - Downloading simplesamlphp/simplesamlphp-module-authwindowslive (v0.9.1)
  - Downloading simplesamlphp/simplesamlphp-module-authtwitter (v0.9.3)
  - Downloading simplesamlphp/simplesamlphp-module-authorize (v0.9.4)
  - Downloading simplesamlphp/simplesamlphp-module-authfacebook (v0.9.3)
  - Downloading whitehat101/apr1-md5 (v1.0.0)
  - Downloading simplesamlphp/simplesamlphp-module-authcrypt (v0.9.4)
  - Downloading simplesamlphp/simplesamlphp-module-adfs (v0.9.9)
  - Downloading robrichards/xmlseclibs (3.1.1)
  - Downloading simplesamlphp/saml2 (v4.4.0)
  - Downloading simplesamlphp/assert (v0.0.13)
  - Downloading phpmailer/phpmailer (v6.5.3)
  - Downloading gettext/gettext (v4.8.6)
  0/74 [>---------------------------]   0%
  3/74 [=>--------------------------]   4%
 12/74 [====>-----------------------]  16%
 20/74 [=======>--------------------]  27%
 27/74 [==========>-----------------]  36%
 33/74 [============>---------------]  44%
 37/74 [==============>-------------]  50%
 39/74 [==============>-------------]  52%
 43/74 [================>-----------]  58%
 44/74 [================>-----------]  59%
 47/74 [=================>----------]  63%
 51/74 [===================>--------]  68%
 54/74 [====================>-------]  72%
 58/74 [=====================>------]  78%
 62/74 [=======================>----]  83%
 63/74 [=======================>----]  85%
 67/74 [=========================>--]  90%
 73/74 [===========================>]  98%
 74/74 [============================] 100%
  - Installing symfony/polyfill-php72 (v1.24.0): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.24.0): Extracting archive
  - Installing symfony/polyfill-ctype (v1.24.0): Extracting archive
  - Installing twig/twig (v2.14.10): Extracting archive
  - Installing symfony/yaml (v4.4.36): Extracting archive
  - Installing symfony/polyfill-php80 (v1.24.0): Extracting archive
  - Installing symfony/var-exporter (v5.4.2): Extracting archive
  - Installing symfony/deprecation-contracts (v2.5.0): Extracting archive
  - Installing symfony/routing (v5.4.0): Extracting archive
  - Installing symfony/polyfill-php73 (v1.24.0): Extracting archive
  - Installing symfony/http-foundation (v5.4.2): Extracting archive
  - Installing psr/event-dispatcher (1.0.0): Extracting archive
  - Installing symfony/event-dispatcher-contracts (v2.5.0): Extracting archive
  - Installing symfony/event-dispatcher (v5.4.0): Extracting archive
  - Installing symfony/var-dumper (v5.4.2): Extracting archive
  - Installing psr/log (1.1.4): Extracting archive
  - Installing symfony/error-handler (v5.4.2): Extracting archive
  - Installing symfony/http-kernel (v5.4.2): Extracting archive
  - Installing symfony/polyfill-php81 (v1.24.0): Extracting archive
  - Installing symfony/finder (v5.4.2): Extracting archive
  - Installing symfony/filesystem (v5.2.6): Extracting archive
  - Installing psr/container (1.1.2): Extracting archive
  - Installing symfony/service-contracts (v2.5.0): Extracting archive
  - Installing symfony/dependency-injection (v5.4.2): Extracting archive
  - Installing symfony/config (v5.4.2): Extracting archive
  - Installing psr/cache (1.0.1): Extracting archive
  - Installing symfony/cache-contracts (v2.5.0): Extracting archive
  - Installing symfony/cache (v5.4.2): Extracting archive
  - Installing symfony/framework-bundle (v5.4.2): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.24.0): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.24.0): Extracting archive
  - Installing symfony/string (v5.4.2): Extracting archive
  - Installing symfony/console (v5.4.2): Extracting archive
  - Installing twig/extensions (v1.5.4): Extracting archive
  - Installing simplesamlphp/twig-configurable-i18n (v2.3.4): Extracting archive
  - Installing simplesamlphp/simplesamlphp (v1.19.4): Extracting archive
  0/36 [>---------------------------]   0%
 10/36 [=======>--------------------]  27%
 20/36 [===============>------------]  55%
 30/36 [=======================>----]  83%
 35/36 [===========================>]  97%
 36/36 [============================] 100%
  - Installing simplesamlphp/composer-module-installer (v1.1.8): Extracting archive
  - Installing gettext/languages (2.9.0): Extracting archive
  - Installing webmozart/assert (1.10.0): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-statistics (v0.9.6): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-sqlauth (v0.9.4): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-smartattributes (v0.9.2): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-sanitycheck (v0.9.1): Extracting archive
  - Installing phpfastcache/riak-client (3.4.3): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-riak (v0.9.1): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-radius (v0.9.4): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-preprodwarning (v0.9.3): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-oauth (v0.9.3): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-ldap (v0.9.17): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-negotiate (v0.9.12): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-metarefresh (v0.9.7): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-memcookie (v1.2.2): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-memcachemonitor (v0.9.3): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-expirycheck (v0.9.4): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-exampleattributeserver (v1.0.0): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-discopower (v0.10.1): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-consent (v0.9.8): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-consentadmin (v0.9.2): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-cdc (v0.9.2): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-cas (v0.9.1): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-authyubikey (v0.9.3): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-authx509 (v0.9.9): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-authwindowslive (v0.9.1): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-authtwitter (v0.9.3): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-authorize (v0.9.4): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-authfacebook (v0.9.3): Extracting archive
  - Installing whitehat101/apr1-md5 (v1.0.0): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-authcrypt (v0.9.4): Extracting archive
  - Installing simplesamlphp/simplesamlphp-module-adfs (v0.9.9): Extracting archive
  - Installing robrichards/xmlseclibs (3.1.1): Extracting archive
  - Installing simplesamlphp/saml2 (v4.4.0): Extracting archive
  - Installing simplesamlphp/assert (v0.0.13): Extracting archive
  - Installing phpmailer/phpmailer (v6.5.3): Extracting archive
  - Installing gettext/gettext (v4.8.6): Extracting archive
  0/37 [>---------------------------]   0%
 10/37 [=======>--------------------]  27%
 20/37 [===============>------------]  54%
 29/37 [=====================>------]  78%
 37/37 [============================] 100%
26 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package simplesamlphp/simplesamlphp-module-authfacebook is abandoned, you should avoid using it. No replacement was suggested.
Package simplesamlphp/simplesamlphp-module-authwindowslive is abandoned, you should avoid using it. No replacement was suggested.
Package simplesamlphp/simplesamlphp-module-oauth is abandoned, you should avoid using it. No replacement was suggested.
Package simplesamlphp/simplesamlphp-module-riak is abandoned, you should avoid using it. No replacement was suggested.
Package twig/extensions is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
32 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Removing intermediate container af5ffb3ef4e9

How can I debug this problem?

4
  • I know that scripts are not executed because the files that must be copied are not present in the destination folder. BTW I have found that if I repeat composer install a second time the scripts get executed but it doesn't seem to me a very clean solution ...
    – Nik
    Commented Jan 21, 2022 at 8:59
  • No composer.lock file present - that's not a good sign. You should not run composer install without a lock file.
    – Nico Haase
    Commented Jan 21, 2022 at 9:17
  • 1
    Also, why do you need to create new folders manually in the vendor folder? You should never modify these contents in any way, and having a folder for logs there is a huge red flag
    – Nico Haase
    Commented Jan 21, 2022 at 9:20
  • I know it is not a good practice but I am using a (kind of) customized library that force to do so to be used (I mean writing things in the vendor folder) ...
    – Nik
    Commented Jan 21, 2022 at 9:26

1 Answer 1

6

Please have a look at the documentation of Composer scripts. It explains pretty obvious:

post-install-cmd: occurs after the install command has been executed with a lock file present.

If you are using composer install with a lock file not present (as indicated from the console output), this event is not fired.

1
  • It's also pretty useless because when you create a composer project manually, then you don't have a composer.lock file: do you see an event that handles this case? Me no unfortunately
    – funder7
    Commented Jan 17, 2023 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.