Skip to main content

Build the PHP base image with apache-buster using the Dockerfile.base

Since JN blocks some libraries update and pull, follow the following steps to build the base image locally.

Run the following command to build the base PHP image:
Make sure you are in the project root directory before running the command and its a fresh window after changing the proxy

docker build -f Dockerfile.base -t apachebuster8 .

Errors running docker command

If you experience errors when attempting to run the command above, which might include the following errors:

#8 0.852 Warning: copy(): SSL operation failed with code 1. OpenSSL Error messages:
#8 0.852 error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in Command line code on line 1
#8 0.852
#8 0.852 Warning: copy(): Failed to enable crypto in Command line code on line 1
#8 0.854
#8 0.854 Warning: copy(https://getcomposer.org/installer): Failed to open stream: operation failed in Command line code on line 1
#8 0.894 Could not open input file: composer-setup.php
#8 ERROR: executor failed running [/bin/sh -c EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"     php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"     ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"     if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]     then         >&2 echo 'ERROR: Invalid installer checksum'         rm composer-setup.php         exit 1     fi &&     php composer-setup.php && mv composer.phar /usr/local/bin/composer]: exit code: 1
 > [7/8] RUN php composer-setup.php:
#10 0.439 Could not open input file: composer-setup.php
  => ERROR [7/8] RUN php composer-setup.php
 => ERROR [8/8] RUN if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]     then         >&2 echo 'ERROR: Invalid i  0.5s
------
 > [8/8] RUN if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]     then         >&2 echo 'ERROR: Invalid installer checksum'         exit 1     fi &&:
#11 0.472 /bin/sh: 1: Syntax error: end of file unexpected
------
executor failed running [/bin/sh -c if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]     then         >&2 echo 'ERROR: Invalid installer checksum'         exit 1     fi &&]: exit code: 2
curl error 60 while downloading https://getcomposer.org/versions: SSL certificate problem: self signed certificate in certificate chain

The issue

They relate to a similar problem.  Being an issue downloading the composer-setup.php file or anything from getcomposer due to SSL certificate.  These issues can be experienced when executing the command via mobile data (SIM) or local WIFI.

Work around

Essentially the process is attempting to install a composer.phar file in the Docker image.  You can view the current .phar file by going to https://getcomposer.org/versions.  Download the stable composer.phar (i.e /download/2.4.2/composer.phar).  

Move the composer.phar file to the root of the site directory.

Now you’ll need to change the Dockerfile.base.  Block the code at the bottom of the file

# RUN EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" \
#     php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
#     ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" \
#     if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ] \
#     then \
#         >&2 echo 'ERROR: Invalid installer checksum' \
#         rm composer-setup.php \
#         exit 1 \
#     fi && \
#     php composer-setup.php && mv composer.phar /usr/local/bin/composer

Add the following

COPY ./composer.phar /tmp/
RUN mv /tmp/composer.phar /usr/local/bin/composer

Try docker command again

docker build -f Dockerfile.base -t apachebuster8 .

 

 

Solution

While the steps above work... they only work to a point.  The core issue is the certificate.  

In the Dockerfile.base file moving the cert.pem file is what's missing.


# CA Certificate
COPY ./nscacert.pem /etc/ssl/certs/nscacert.pem
RUN  echo "openssl.cafile = /etc/ssl/certs/nscacert.pem" >> /usr/local/etc/php/php.ini

 

php\r 'No such file or directory' error

If you find you have the following error occur when attempting a drush command

drush /usr/bin/env: 'php\r': No such file or directory

Using Terminal, go to the root directory of the site and then into content/.  Now you can install drush using

composer require drush/drush

Once installed, check Drush is running using any command.  I generally use version

drush -V

Response will be similar to

Drush Commandline Tool 11.2.1

 

 

Related articles

Andrew Fletcher17 Mar 2025
Upgrading to PHP 8.4 challenges with Drupal contrib modules
The upgrade from PHP 8.3.14 to PHP 8.4.4 presents challenges for Drupal 10.4 websites, particularly when dealing with contributed modules. While Drupal core operates seamlessly, various contrib modules have not yet been updated to accommodate changes introduced in PHP 8.4.x. This has resulted in...
Andrew Fletcher20 Feb 2025
Handling duplicate records in Drupal
Duplicate records in Drupal can cause significant issues, particularly when they lead to integrity constraint violations in the database. These errors often occur due to duplicate UUIDs in the `node` table, which can result from programmatic imports, migrations, or unintended database...
Andrew Fletcher17 Feb 2025
The overlooked challenge of migration updates in Drupal projects
When working on Drupal migrations, developers often assume that adding a new field to the process section will seamlessly update existing content. However, unless explicitly handled, Drupal’s migration system does not automatically apply changes to previously migrated records. This oversight can...