I'm encountering an issue with my Docker setup where the container exits unexpectedly after executing a custom entrypoint script and the original entrypoint provided by the base image.
Dockerfile:
FROM pimcore/pimcore:php8.2-latest
ENV PATH="./vendor/bin:${PATH}" \
NGINX_SERVER_NAME="prod" \
PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
PHP_OPCACHE_MAX_ACCELERATED_FILES="6000" \
PHP_OPCACHE_MEMORY_CONSUMPTION="128" \
PHP_FPM_PM_MAX_CHILDREN=30 \
PHP_FPM_PM_START_SERVERS=15 \
PHP_FPM_PM_MIN_SPARE_SERVERS=15 \
PHP_FPM_PM_MAX_SPARE_SERVERS=25 \
PHP_FPM_PM_MAX_REQUESTS=500
# PHP_MEMORY_LIMIT=512M
COPY ./ /var/www/html
COPY ../docker/php/www.conf /usr/local/etc/php-fpm.d/www.conf
RUN find /var/www/html -print | xargs --max-args=1 --max-procs=10000 -i chown -R 33:33 "{}" | true
COPY pimcore/configure_memory.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/configure_memory.sh
ENTRYPOINT ["/usr/local/bin/configure_memory.sh", "/usr/local/bin/docker-php-entrypoint"]
configure_memory.sh:
#!/bin/bash
echo "Configuring memory..."
# Perform any additional checks or configurations here
if [ "$(awk '/MemTotal/ {print $2}' /proc/meminfo)" -ge 16000000 ]; then
echo "Setting memory_limit to 512M"
echo "memory_limit = 512M" >> /usr/local/etc/php/conf.d/20-pimcore.ini
#modify ENV variables
else
echo "Setting memory_limit to 256M"
echo "memory_limit = 256M" >> /usr/local/etc/php/conf.d/20-pimcore.ini
#modify ENV variables
fi
echo "Executing the original command: $@"
# Execute the CMD of the Docker image
exec "$@"
The container exits with code 0 after executing both the custom entrypoint script (configure_memory.sh
) and the original entrypoint (docker-php-entrypoint
).
Please note that I don't want to override the original image CMD and ENTRYPOINT. I want to first just execute the custom configure_memory.sh
script at runtime to properly assign the memory_limit
and the the original image CMD and ENTRYPOINT to continue. The reason for this is that I use the same image on two different app services—one with 16GB of memory and the other with 3.5GB. I need to dynamically configure the memory_limit
based on the available memory during runtime.
Is there a better way to configure the **memory
limit
***, max_*children( and the other variables) for this scenario, or am I on the right track with the current approach?
The
ENTRYPOINT
documentation notesYou need to find the Dockerfile for the base image, or
docker inspect
it to find its entrypoint. For this image, its Docker Hub page points at a GitHub repository that contains a Dockerfile. Thepimcore_php_default
stage ends withand you need to repeat this in your own Dockerfile. (Note that stage does not seem to obviously declare an
ENTRYPOINT
.)