Skip to content

How to Fix Docker Entrypoint Script Not Executing

DodaTech Updated 2026-06-24 2 min read

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 +x in 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

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. 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

### Shell form vs exec form: what is the difference?

Shell form (ENTRYPOINT /entrypoint.sh) wraps the command in /bin/sh -c, cannot receive signals from docker stop, and does not pass CMD arguments. Exec form (ENTRYPOINT ["/entrypoint.sh"]) runs the command directly with proper signal handling.

How do I pass arguments to an entrypoint script?

CMD is passed as arguments to ENTRYPOINT. In the script, use "$@" to forward all arguments. Example: docker run myapp --debug passes --debug to the entrypoint script.

Why does my entrypoint work locally but not in production?

Check line endings (Git may convert to CRLF on Windows, use .gitattributes with * text=auto eol=lf), file permissions (Git may lose execute bit), and available shell (Alpine uses sh not bash).

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro