Trying to run Docker resulted in exit code 127

I faced the same error while building in AWS CodeBuild. The issue was the sudo in the commands

In the buildspec.yml file, I had to change:

sudo docker build -t xxxx:xxxx

to

docker build -t xxxx:xxxx

I think the 127 means docker was not found on the path. Similar question. On windows docker will only work inside the boot2docker vm so if you are running the script in cygwin it would not work. You must ssh into the boot2docker vm and run your commands there.


Make sure your file has the correct line ending.

For example, open your file using Vim and run: :set fileformat=unix, then save the file and run Docker again.


I got almost the same issue, the problem was simply in windows ending in that file, it was using CRLF instead of LF, change it to LF and it might work (using Notepad++, IntelliJ or Visual Code), referring to these answers:

env: bash\r: No such file or directory

How do I set all files in a subdirectory to use a specific eol using gitattributes?

So my .gitattributes file now is like this:

* text=auto
/docker/* text eol=lf
/ci/* text eol=lf
/sbt text eol=lf
/docker-*.sh text eol=lf
/sbt-dist/bin/*.bash text eol=lf
/sbt-dist/bin/sbt text eol=lf

These attributes because I have play framework project deployed in docker.