Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Docker image doesn't inherit CMD

I have an image built using the following Dockerfile:

FROM php:7-fpm
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
ENTRYPOINT ["docker-entrypoint"]

It uses a custom entrypoint which is the following bash script:

#!/bin/bash
set -e
echo "STARTING PHP FPM, CMD $@"
docker-php-entrypoint "$@"

The command of the parent image defined in it's Dockerfile is CMD ["php-fpm"]

Now I expected this command to be inherited in my image. However, when I run the image, the command is empty. Here is the output of the docker run command:

STARTING PHP FPM, CMD

However, if I copy CMD ["php-fpm"] to the end of my custom Dockerfile, the output is

STARTING PHP FPM, CMD php-fpm

[01-Nov-2017 20:04:02] NOTICE: fpm is running, pid 7

[01-Nov-2017 20:04:02] NOTICE: ready to handle connections

Why isn't the parent's CMD directive inherited?

like image 951
super.t Avatar asked Nov 01 '17 20:11

super.t


1 Answers

This behavior is trying to be more intuitive, but I agree that it's a bit confusing. You see the original issue here. That problem was that most people defining the ENTRYPOINT in a child image no longer wanted the CMD from the parent image.

With the current behavior, if you define an ENTRYPOINT in a child image, the CMD from the parent image will be null'd out, so you'll need to redefine it if you need to have it set.

like image 134
BMitch Avatar answered Nov 16 '22 23:11

BMitch