Programster's Blog

Tutorials focusing on Linux, programming, and open-source

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.

Solution

Add a .gitattributes file to the top of your repository with the following contents.

* text=auto
*.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

References

Last updated: 21st April 2023
First published: 2nd June 2020

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch