A Docker container will not run its entrypoint.sh script
permission deniedShort answer
Most often the script was copied into the image without the execute bit, so the kernel refuses to run it. Set the mode when you copy it, and keep the bit in Git. Two other causes look similar: a bind mount can hide the image's copy of the script, and shell-form ENTRYPOINT ignores CMD arguments.
Fix it fast
1Find out which cause you have
Look at the file inside the image, bypassing the entrypoint. The mode column shows whether the execute bit is set.
docker run --rm --entrypoint ls my-image -l /usr/local/bin/docker-entrypoint.sh docker inspect --format '{{ .Config.Entrypoint }}' my-image2Match what you see, then jump to its fix
- 1
ls -l shows -rw-r--r-- with no x, and starting the container ends in permission denied.The script is in the image without the execute bitFix - 2
The image works alone, but fails or runs an old script when the same folder is mounted with -v or a compose volume.A bind mount hides the script that was baked into the imageFix - 3
The script starts, but the command after the image name in docker run, or CMD, never reaches it, or the program does not react to docker stop.Shell-form ENTRYPOINT ignores the arguments you passFix
- 1
What does the error look like?
permission deniedthe container exits at once and the entrypoint script does not run
Cause 1 of 3
The script is in the image without the execute bit
1Check
COPY keeps the mode of the file in your build context. A file saved without x, or checked out on a system that does not track modes, arrives without x.
ls -l docker-entrypoint.sh2Fix
Set the mode in the Dockerfile with the COPY --chmod flag, which takes octal or symbolic values. Also record the bit in Git so every checkout has it.
COPY --chmod=755 docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
# once, in the repository
git update-index --chmod=+x docker-entrypoint.sh3Verify
The bit is set in the rebuilt image and the container starts.
docker build -t my-image .
docker run --rm --entrypoint ls my-image -l /usr/local/bin/docker-entrypoint.shConfirmed by docs.docker.com
Cause 2 of 3
A bind mount hides the script that was baked into the image
1Check
A bind mount over a folder that already has files in the image hides those files. If the host folder has its own copy of the script, that copy is used, with whatever mode it has.
docker inspect --format '{{ json .Mounts }}' my-container2Fix
Mount over a different path than the one that holds the script, or fix the file on the host. Removing the mount shows the image's own files again.
# compose.yaml: keep the script's folder out of the mount
services:
app:
image: my-image
volumes:
- ./src:/app/src3Verify
Start the container with the changed volumes.
docker compose up appConfirmed by docs.docker.com
Cause 3 of 3
Shell-form ENTRYPOINT ignores the arguments you pass
1Check
Shell form runs the entrypoint as a subcommand of /bin/sh -c. It ignores CMD and docker run arguments, and the program is not PID 1, so it does not receive SIGTERM.
grep -n "^ENTRYPOINT\|^CMD" Dockerfile2Fix
Use exec form, and call exec at the end of the script so the final process takes over as PID 1.
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["server", "--port", "8080"]
# last line of docker-entrypoint.sh
exec "$@"3Verify
Arguments reach the script.
docker run --rm my-image server --port 9090Confirmed by docs.docker.com
How do I stop it coming back?
- Use COPY --chmod for every script copied into an image, so the build does not rely on file modes from the checkout.
- Keep scripts on a filesystem that tracks the execute bit, or set it with git update-index --chmod=+x.
- Write ENTRYPOINT in exec form and keep the default arguments in CMD.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
A Docker container exits with 'no such file or directory' though the file exists
standard_init_linux.go:190: exec user process caused "no such file or directory"
The kernel returns this error when the file's interpreter is missing, not only the file.
3 causes, each with a fixServers
A container starts and stops at once with exec format error
exec /usr/bin/sh: exec format error
The kernel was asked to run a file it cannot execute.
4 causes, each with a fixServers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fix