How to Fix Docker Entrypoint Script Not Executing
In this tutorial, you'll learn about How to Fix Docker Entrypoint Script Not Executing. We cover key concepts, practical examples, and best practices.
Your Docker container starts but your entrypoint script is ignored or runs with errors — the script lacks execute permission, has a wrong shebang, or is overridden by the CMD.
The Problem
docker: Error response from daemon: failed to create shim: OCI runtime create failed:
container_linux.go:380: starting container process caused: exec: "./entrypoint.sh":
permission denied: unknown
Step-by-Step Fix
Step 1: Make the entrypoint executable
Dockerfile fix:
# WRONG — missing execute permission
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
# RIGHT — add execute permission
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
Step 2: Use the correct shebang
#!/bin/bash
Or for Alpine (no bash):
#!/bin/sh
Test inside the container:
docker run --rm --entrypoint head myapp -1 /entrypoint.sh
Expected:
#!/bin/sh
Step 3: Use JSON array syntax for ENTRYPOINT
# WRONG — shell form, signal handling broken
ENTRYPOINT /entrypoint.sh
# RIGHT — exec form, proper signal handling
ENTRYPOINT ["/entrypoint.sh"]
Shell form wraps the command in /bin/sh -c, which does not forward signals correctly.
Step 4: Handle the main process in the script
#!/bin/bash
# Do pre-start setup
echo "Running migrations..."
# exec replaces the shell with the main process for proper signal handling
exec "$@"
Pass CMD as arguments:
ENTRYPOINT ["/entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
Step 5: Debug with a custom entrypoint override
docker run --rm --entrypoint cat myapp /entrypoint.sh
This prints the script content without executing it.
Prevention Tips
- Always use
RUN chmod +xin the Dockerfile - Use exec-form (
["..."]) for ENTRYPOINT - Use
exec "$@"at the end of entrypoint scripts - Test the script locally before building
- Check line endings — Windows CRLF will break scripts in Linux
Common Mistakes with entrypoint error
- Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
These mistakes appear frequently in real-world DOCKER code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro