How to execute script during image build in Docker

I have the following at the end of mine Dockerfile:

ENTRYPOINT bash -C '/usr/local/bin/setup_php_settings';'bash'

If I'm not mistaken, that /usr/local/bin/setup_php_settingswill be executed every time the container starts. If so, I have several installation materials (for example this ZRay, for example) inside this script that I would like to move to another script that will be executed only once during the image assembly process, say.

The content setup_php_settings(without the ZRay part) is as follows:

#!/bin/bash -x
set -e

PHP_ERROR_REPORTING=${PHP_ERROR_REPORTING:-"E_ALL & ~E_DEPRECATED & ~E_NOTICE"}
sed -ri 's/^display_errors\s*=\s*Off/display_errors = On/g' /etc/php5/apache2/php.ini
sed -ri 's/^display_errors\s*=\s*Off/display_errors = On/g' /etc/php5/cli/php.ini
sed -ri "s/^error_reporting\s*=.*$//g" /etc/php5/apache2/php.ini
sed -ri "s/^error_reporting\s*=.*$//g" /etc/php5/cli/php.ini
echo "error_reporting = $PHP_ERROR_REPORTING" >> /etc/php5/apache2/php.ini
echo "error_reporting = $PHP_ERROR_REPORTING" >> /etc/php5/cli/php.ini

mkdir -p /data/tmp/php/uploads
mkdir -p /data/tmp/php/sessions
mkdir -p /data/tmp/php/xdebug
chown -R www-data:www-data /data/tmp/php*

ln -sf /etc/php5/mods-available/zz-php.ini /etc/php5/apache2/conf.d/zz-php.ini
ln -sf /etc/php5/mods-available/zz-php-directories.ini /etc/php5/apache2/conf.d/zz-php-directories.ini
ln -sf /usr/share/php/libzend-framework-php/Zend/ /usr/share/php/Zend
a2enmod rewrite
php5enmod mcrypt

# Apache gets grumpy about PID pre-existing files
: "${APACHE_PID_FILE:=${APACHE_RUN_DIR:=/var/run/apache2}/apache2.pid}"
rm -f "$APACHE_PID_FILE"

source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND "$@"

The question is, how can I execute such a new script during image assembly? Using CMD? Any other workaround?

+4
1

- RUN. script . -

RUN /usr/local/bin/setup_php_settings
CMD bash
+5

Source: https://habr.com/ru/post/1658820/


All Articles