Docker on Windows: /usr/bin/env: bash\r No such file or directory
Getting the following error when you want to start your Docker container on Windows: /usr/bin/env: bash\r : No such file or directory
I discovered that another fix is to do dos2unix <file>
dos2unix <file with the issues>
Try that if you’re on Windows or working with others who work on Windows.
[/edit]I found several topics with several fixes. But what fixed it for me was:
Solution: Setting the line-endings correctly
- In my editor:
\n
- In git:
git config --global core.autocrlf false
I chose the \n
line ending as this is stated in PSR-12: 2.2 Files:
All PHP files MUST use the Unix LF (linefeed) line ending only.
I use PHPStorm and had to go to
Settings > Editor > Code Style > tab General > Unix and macOS (\n)

NOTE: you may have to do the following to fix files with the wrong line-endings:
- remove the built Docker image on Windows: first list
docker images
and then delete:docker rmi <imagename>
- fix the line-ending of the file. You might do that by removing the newline and adding a new one. Don’t forget to
save
,commit
andpush