Docker: Entrypoint's override involve CMD specification?










2















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.











share|improve this question






















  • Without having CMD [ "php-fpm" ] in your docker file can you 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.

    – George Appleton
    Nov 14 '18 at 11:06












  • Possible duplicate: Is CMD in parent docker overriden by CMD/ENTRYPOINT in child docker image?

    – BMitch
    Nov 14 '18 at 12:16















2















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.











share|improve this question






















  • Without having CMD [ "php-fpm" ] in your docker file can you 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.

    – George Appleton
    Nov 14 '18 at 11:06












  • Possible duplicate: Is CMD in parent docker overriden by CMD/ENTRYPOINT in child docker image?

    – BMitch
    Nov 14 '18 at 12:16













2












2








2








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.











share|improve this question














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 dockerfile docker-entrypoint






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 10:54









Sim ScaSim Sca

131311




131311












  • Without having CMD [ "php-fpm" ] in your docker file can you 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.

    – George Appleton
    Nov 14 '18 at 11:06












  • Possible duplicate: Is CMD in parent docker overriden by CMD/ENTRYPOINT in child docker image?

    – BMitch
    Nov 14 '18 at 12:16

















  • Without having CMD [ "php-fpm" ] in your docker file can you 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.

    – George Appleton
    Nov 14 '18 at 11:06












  • Possible duplicate: Is CMD in parent docker overriden by CMD/ENTRYPOINT in child docker image?

    – BMitch
    Nov 14 '18 at 12:16
















Without having CMD [ "php-fpm" ] in your docker file can you 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.

– George Appleton
Nov 14 '18 at 11:06






Without having CMD [ "php-fpm" ] in your docker file can you 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.

– George Appleton
Nov 14 '18 at 11:06














Possible duplicate: Is CMD in parent docker overriden by CMD/ENTRYPOINT in child docker image?

– BMitch
Nov 14 '18 at 12:16





Possible duplicate: Is CMD in parent docker overriden by CMD/ENTRYPOINT in child docker image?

– BMitch
Nov 14 '18 at 12:16












1 Answer
1






active

oldest

votes


















2














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.






share|improve this answer























  • Thank you, and thanks for the link!

    – Sim Sca
    Nov 14 '18 at 13:16










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298532%2fdocker-entrypoints-override-involve-cmd-specification%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














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.






share|improve this answer























  • Thank you, and thanks for the link!

    – Sim Sca
    Nov 14 '18 at 13:16















2














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.






share|improve this answer























  • Thank you, and thanks for the link!

    – Sim Sca
    Nov 14 '18 at 13:16













2












2








2







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 12:15









BMitchBMitch

64.2k10138159




64.2k10138159












  • Thank you, and thanks for the link!

    – Sim Sca
    Nov 14 '18 at 13:16

















  • Thank you, and thanks for the link!

    – Sim Sca
    Nov 14 '18 at 13:16
















Thank you, and thanks for the link!

– Sim Sca
Nov 14 '18 at 13:16





Thank you, and thanks for the link!

– Sim Sca
Nov 14 '18 at 13:16



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298532%2fdocker-entrypoints-override-involve-cmd-specification%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo