这是我纯粹好奇的问题:
我必须个性化 Docker 映像,特别是这是我的 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"
原始图像是PHP-FPM-ALPINE
有命令
CMD [ "php-fpm" ]
我的问题是,当我运行这个图像时(好吧,我们正确运行容器,而不是图像,我知道)默认命令不会传递给my-entrypoint.sh
,实际上输出是:
Trying my-entrypoint with args:
Enabling XDEBUG
Execute Main:
Main Done
即ENTRYPOINT没有收到默认命令php-fpm
,所以主进程自动停止。
但是如果我修改 dockerfile 添加CMD
在最后:
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
一切顺利(即 CMD 被传递到入口点):
Trying my-entrypoint with args: php-fpm
Enabling XDEBUG
Execute Main:
最后我的问题是:
为什么我必须重新声明CMD ["php-fpm"]
如果我改变ENTRYPOINT
指示?
注意CMD ["php-fpm"]
与原始图像相同。