This might be caused by a number of things - such as:
- Wrong line endings (Windows vs Unix)
If you're building on Windows, your
startup.sh
file might have CRLF line endings (carriage return + line feed), which Linux doesn't like.
Convert the script to Unix line endings (LF):
- In VS Code: Bottom-right corner > Click on
CRLF
> Select LF
.
- Or run this on WSL/Linux/macOS:
dos2unix startup.sh
- File not copied correctly
Double-check that the
COPY
instruction in the Dockerfile is correct and matches the path.
Example Dockerfile:
# Base image
FROM ubuntu:latest
# Copy startup script
COPY startup.sh /usr/local/bin/startup.sh
# Set permissions
RUN chmod +x /usr/local/bin/startup.sh
# Set entrypoint
ENTRYPOINT ["/usr/local/bin/startup.sh"]
Make sure startup.sh
is in the same folder as your Dockerfile, or adjust the COPY
path.
- Interpreter missing (e.g.,
#!/bin/sh
or #!/bin/bash
)
Check the first line of your script. It must start with a proper shebang (interpreter directive):
#!/bin/sh
or
#!/bin/bash
And ensure that /bin/sh
or /bin/bash
actually exists in your base image (e.g., Alpine uses /bin/sh
, not Bash).
To debug in the Dockerfile, add this temporarily to your Dockerfile
before the ENTRYPOINT
:
RUN ls -l /usr/local/bin/startup.sh && head -n 1 /usr/local/bin/startup.sh && file /usr/local/bin/startup.sh
It'll give you insight into:
- Whether the file exists
- What the first line looks like (to see the shebang)
- If it has Windows line endings (
with CRLF line terminators
)
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin