That's a question for my pure curiousity:
I have to personalize a Docker Image, in particular this is an extract of my dockerfile:
ARG DEFAULT_PHP_VERSION
FROM php:${DEFAULT_PHP_VERSION:+${DEFAULT_PHP_VERSION}-}fpm-alpine
# RUN some personal stuff
RUN rm -rf /var/www/html
# Set proper Entrypoint
COPY build/fs/usr/local/bin/my-entrypoint.sh /usr/local/bin/my-entrypoint.sh
RUN chmod +x /usr/local/bin/my-entrypoint.sh
ENTRYPOINT [ "my-entrypoint.sh" ]
WORKDIR /var/www
and my-entrypoint.sh
is:
#!/bin/sh
set -e
echo "Trying my-entrypoint with args: $@"
if [ ! -z "$XDEBUG_ENABLED" ] ; then
echo "Enabling XDEBUG"
docker-php-ext-enable xdebug
fi
# execute default entrypoint
echo "Execute Main:"
docker-php-entrypoint $@
echo "Main Done"
the original image is PHP-FPM-ALPINE
that has the command
CMD [ "php-fpm" ]
My problem is that when i run this image (ok, we properly run containers, not images, I know) the default command is not passed to my-entrypoint.sh
, in fact the output is:
Trying my-entrypoint with args:
Enabling XDEBUG
Execute Main:
Main Done
That is the ENTRYPOINT doesn't receive the default command php-fpm
, and so the main process automatically stops.
BUT if I modify the dockerfile adding the CMD
at the end:
ARG DEFAULT_PHP_VERSION
FROM php:${DEFAULT_PHP_VERSION:+${DEFAULT_PHP_VERSION}-}fpm-alpine
# RUN some personal stuff
RUN rm -rf /var/www/html
# Set proper Entrypoint
COPY build/fs/usr/local/bin/my-entrypoint.sh /usr/local/bin/my-entrypoint.sh
RUN chmod +x /usr/local/bin/my-entrypoint.sh
ENTRYPOINT [ "my-entrypoint.sh" ]
CMD ["php-fpm"]
WORKDIR /var/www
and all goes right (that is the CMD is passed to entrypoint):
Trying my-entrypoint with args: php-fpm
Enabling XDEBUG
Execute Main:
why I have to redeclare the CMD ["php-fpm"]
if I change the ENTRYPOINT
directive?
note that
CMD ["php-fpm"]
is the same in original IMAGE.
This is one of the exception cases when inheriting values from a previous image. If the parent image defines a CMD
, and your image defines an ENTRYPOINT
, then the value of CMD
is nulled out. In all other scenarios, you should see ENTRYPOINT
and CMD
inherited from parent images unchanged. For the logic behind this decision, please see issue 5147.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With