entrypoint.sh does not see a copied file

I have a Dockerfile containing:

FROM php:7.4-fpm-alpine
...
COPY somefile /somefile
COPY --chmod=0755 entrypoint.sh /entrypoint.sh
ENTRYPOINT /entrypoint.sh

entrypoint.sh contains:

#!/bin/sh
sed -i 's/something/something else/' /somefile

When I build and run the container with docker compose, both COPY‘s definitely succeed: /somefile and /entrypoint.sh are in the container’s root directory with the right permissions and content — I have checked this by getting into the container built without the ENTRYPOINT. Moreover, from within the container, /entrypoint.sh runs successfully.

However, when the container is built with the ENTRYPOINT, it fails to run with sed: /somefile: No such file or directory.

For some reason, /entrypoint.sh, when run by Docker, does not see the world-visible /somefile. Why could that be?

  • 1

    Please post the exact output from docker build and docker run including all command line options and verbatim full output. Please add ls -la / to entrypoint and post the output. Is somefile a symlink? Please post docker version and your kernel version. Can you reproduce with alpine image?

    – 

  • @KamilCuk, thank you, ls -la / helped me to understand that the real problem is not the lost file but the fact that the container stopped (and then was restarted by docker compose; and the file was removed at the end of the entrypoint.sh thus becoming unavailable to the next incarnation of the container). I think, I will remove the question as it will be of no use to anyone.

    – 

Leave a Comment