我的 Dockerfile
末尾有以下内容:
ENTRYPOINT bash -C '/usr/local/bin/setup_php_settings';'bash'
如果我没记错的话
/usr/local/bin/setup_php_settings
每次启动容器时都会执行。如果是这样,那么我在该脚本中有一些安装内容(例如 this ZRay),我想移动到另一个脚本,该脚本在图像构建过程中只执行一次。setup_php_settings
的内容(不含 ZRay 部分)如下:#!/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 "$@"
问题是,如何在镜像构建期间执行这样的新脚本?使用
CMD
?还有其他解决方法吗?
最佳答案
正确的指令是 RUN
.这将在图像构建上运行脚本。在你的情况下 -
RUN /usr/local/bin/setup_php_settings
CMD bash
关于docker - 如何在 Docker 中构建镜像期间执行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40239781/