Docker Compose启动报错:./entrypoint.sh未找到但文件存在
Alright, let's dig into this "entrypoint not found" issue you're hitting. I've seen this pop up a few times with Windows + Docker setups, so let's break down the likely causes and fixes:
You mentioned seeing entrypoint.sh listed when running ls, but the error says ./entrypoint: not found—that's a red flag. Double-check your docker-compose.yml to make sure your entrypoint directive points to the correct filename:
# ❌ Wrong (if your file is named entrypoint.sh) entrypoint: ./entrypoint # ✅ Correct entrypoint: ./entrypoint.sh
Windows uses CRLF line endings by default, but Linux-based containers expect LF. If you created entrypoint.sh on Windows, the hidden carriage returns can break the shell's ability to interpret the script—even though the file exists.
Quick fixes:
- Use a text editor like VS Code: Open the file, click the "CRLF" indicator in the bottom-right corner, switch to "LF", then save.
- If using Git, configure it to not convert line endings for this repo:
git config core.autocrlf false - If you're building a custom image, add a line to your Dockerfile to clean up line endings:
RUN sed -i 's/\r$//' entrypoint.sh
Even if the file exists, the container's shell won't run it without execute permissions.
How to fix:
- If you're on Windows, use Git Bash or WSL to run this command on your local file:
chmod +x entrypoint.sh - If you're mounting the script via a volume, you can adjust your docker-compose entrypoint to set permissions first:
entrypoint: ["sh", "-c", "chmod +x ./entrypoint.sh && ./entrypoint.sh"]
Ensure the container's working directory matches where your entrypoint.sh is located. If you're mounting a local folder to a specific path in the container (like /app), either:
- Use the full path to the script in your entrypoint:
/app/entrypoint.sh - Add a
working_dirdirective to your docker-compose service:services: mssql: # ... other config ... working_dir: /app entrypoint: ./entrypoint.sh
To narrow down the issue, modify your entrypoint to run debug commands first:
entrypoint: ["sh", "-c", "ls -l && cat entrypoint.sh && ./entrypoint.sh"]
This will show you the file permissions, the exact content of the script (including any hidden line endings), and then attempt to run it—this should help you spot exactly what's going wrong.
内容的提问来源于stack exchange,提问作者Kristof Plennings

