Docker Community Forums

Share and learn in the Docker community.

The container based on php:5.6-apache is not running when I try to execute shell script with using CMD instruction

I have DockerFile

FROM php:5.6-apache

SHELL ["/bin/bash", "-c"]

...

COPY start.sh /root/init.sh

RUN chmod 700 /root/init.sh

RUN /root/init.sh # WORKING IF CMD IS ABSENT !!!

COPY start.sh /root/start.sh

RUN chmod 700 /root/start.sh

CMD /root/start.sh # <-- NOT WORKING (((

The image is building well.

The container is not starting if I have CMD instruction, without any logs! If I skip the CMD instruction, container is working well, BUT I need to run start.sh every time when the container run. How can I resolve this issue?

init.sh:

#!/bin/bash

touch /root/$RANDOM-init.txt

start.sh:

#!/bin/bash

touch /root/$RANDOM-start.txt

CMD is basically a parameter for whatever is defined as ENTRYPOINT, which itself defaults to some /bin/sh -c if not set by the base image. So, do you know what ENTRYPOINT is defined by that image? Rather than setting CMD, didn’t you intend to replace the image’s entrypoint instead?

That I don’t understand. RUN is used while building the image, not while running it using the combination of ENTRYPOINT and CMD. Are you sure you’re not running into build caching? See also Leverage build cache in the documentation.

Also, are sure you want to copy start.sh into both /root/init.sh and /root/start.sh? That’s what you’re doing:

Also, since you’re only touching, the container will exit right efter it touches