When working with Docker, you may encounter this cryptic error:
standard_init_linux.go:178: exec user process caused "exec format error"
This error usually occurs when the binary or script inside the container is not compatible with the container’s runtime environment. Let’s break it down and see how to fix it.
1️⃣ Why Does This Error Happen?
This error means Docker tried to start a process, but the file it executed was not in a valid format for the container’s OS or CPU architecture.
Common causes:
- 🏗️ Architecture mismatch – e.g., building an ARM image but running on x86_64.
- 📄 Bad script interpreter – the script has the wrong shebang (
#!) line or is missing it. - 🔒 Windows vs Linux line endings – using CRLF instead of LF in shell scripts.
- 🚫 Binary not executable – missing executable permissions.
2️⃣ Common Fixes
✅ Check CPU Architecture
If you’re building on a different platform (e.g., Mac M1 ARM vs Linux x86), ensure the image matches the host’s architecture.
To check:
docker run --rm alpine uname -m
If needed, build for a specific platform:
docker buildx build --platform linux/amd64 -t myimage .
✅ Fix Shell Script Shebang
If your entrypoint script starts with:
#!/bin/bash
but /bin/bash doesn’t exist inside the container, it will fail.
Instead, use:
#!/bin/sh
(since sh is always available in minimal images like Alpine).
✅ Convert Line Endings (Windows vs Linux)
If you created your script on Windows, it may have CRLF (\r\n) endings instead of LF (\n).
Convert it:
dos2unix script.sh
Or in Git, enforce LF with:
git config --global core.autocrlf input
✅ Add Execute Permission
Make sure your script is executable before copying into the image:
chmod +x entrypoint.sh
In your Dockerfile:
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
3️⃣ Debugging the Issue
If you’re unsure what’s wrong, try running the script manually inside the container:
docker run -it --entrypoint sh myimage
Then:
cat -A /usr/local/bin/entrypoint.sh
This shows line endings and hidden characters.
Or check file type:
file /usr/local/bin/entrypoint.sh
📌 Summary
The error
standard_init_linux.go:178: exec user process caused "exec format error"
usually means:
- ❌ Wrong CPU architecture
- ❌ Incorrect shebang in scripts
- ❌ Windows CRLF line endings
- ❌ Missing executable permissions
✅ To fix, ensure the right architecture, use correct shebangs, convert line endings, and set proper permissions.