6

I have a relatively simple dockerfile

FROM python:3.6.5-alpine

COPY somebinary /usr/local/bin/

COPY install.sh /install.sh
RUN /install.sh

The binary gets copied across just fine (when I run the container to check) but the script doesn't seem to get copied across so that when I try to run it I get:

Step 4/5 : COPY install.sh /install.sh
 ---> 38ecc6dbad13
Step 5/5 : RUN /install.sh
 ---> Running in 0b06962d6e1b
/bin/sh: /install.sh: not found
The command '/bin/sh -c /install.sh' returned a non-zero code: 127

The same happens with any other test files I make, they aren't available when the image is run. Other people have had success running the exact same script so I suspect it could be to do with the fact that I'm running docker through Git Bash on Windows? Could it be a permissions thing?

e: I went and tried running through powershell and got the same error, so perhaps git bash is a red herring

ptr
  • 3,292
  • 2
  • 24
  • 48
  • 127 means command not found are you sure you have this bash and file is in correct path ? – Anar Bayramov May 22 '18 at 06:56
  • What do you mean by the file is in the correct path? It's in the same folder as my dockerfile so it's in the context. It isn't on the container though and I can't work out why. – ptr May 22 '18 at 06:57
  • Just made an edit- I tried it through powershell and got the same problems so I'm not sure it is git bash after all – ptr May 22 '18 at 07:24

1 Answers1

6

It seems your install.sh script is having ^M characters.
Try saving your install.sh into unix format. dos2unix

Use notepad++ or sublime or any other editor which support converting end of lines from Windows to UNIX format.

fly2matrix
  • 2,351
  • 12
  • 13
  • Ouch, yeah this was it! Thanks, will have to work out the best way of converting the line endings at build time since there's always a chance the images will be built on windows – ptr May 22 '18 at 07:47
  • 1
    I would suggest using the .gitattributes file with *.sh text eol=lf -- this means anyone who checks out the repo gets the shell scripts with LF line endings regardless of OS – Mark Simpson Nov 27 '18 at 15:45
  • Only caveat I have for this advice is that you must be running a new-ish version of git. Old versions won't understand it (it's not destructive, just means things won't be checked out as intended) – Mark Simpson Dec 03 '18 at 16:25