Docker - Fixing Windows Line Endings In BASH Scripts When Using Volumes
If you use Docker on Windows, and mount your application's code through a volume, you may find that you can't run your code's BASH scripts, and configuration files. This is because when the code was checked out through git, it placed the OS's native line endings on the files.
.gitattributes file to the top of your repository with the following contents.
*.sh text eol=lf
*.conf text eol=lf
Now commit that and go re-check-out your codebase before trying again.
Set Line Endings To Linux On Checkout
You may be interested in configuring git to globally
git config --global core.autocrlf input
- Medium - The case of Windows line-ending in bash-script
- GitHub Docs - Configuring Git to handle line endings
First published: 2nd June 2020