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:
Finally my question:
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.
docker exec -it containerName sh
for me and check what docker-php-entrypoint is, should be located somewhere like /usr/local/bin/docker-php-entrypoint. Presumably this is changing, compare the differences. Else, try outputting exactly what $@ is to see what's the difference is there. – Lema