1

At windows 10, when I run:

$ docker build .

I get this error in console:

 RUN /provision/provision.sh
 ---> Running in e66928c3c893
/bin/sh: 1: /provision/provision.sh: not found

My folder files:

/Dockerfile
/provision
/provision/provision.sh

So why I get /bin/sh: 1: /provision/provision.sh: not found error, although /provision/provision.sh exists ?

EDIT

I tried: ADD provision /provision

And I tried:

COPY provision /provision

Didn't work..

Step 7 : COPY provision /provision
 ---> c5d07de6948d
Removing intermediate container 85768981a7f0
Step 8 : RUN /provision/provision.sh
 ---> Running in 8426a8526514
/bin/sh: 1: /provision/provision.sh: not found
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
The command '/bin/sh -c /provision/provision.sh' returned a non-zero code: 127
simo
  • 23,342
  • 38
  • 121
  • 218

2 Answers2

2

provision/provision.sh exists in your docker build context (on your host), but you need to copy (COPY) it first to the image:

COPY provision/provision.sh /provision/provision.sh
# or
COPY provision /provision/
RUN chmod 755 /provision/provision.sh && \
    /provision/provision.sh

As mentioned in the doc:

If <src> is a directory, the entire contents of the directory are copied, including filesystem metadata.

Note: The directory itself is not copied, just its contents.

RUN will execute a command in an intermediate container launched with the Dockerfile content compiled up to that line.
It means it execute something in the context of the container, not in the context of your host.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Kindly check EDIT above – simo Feb 20 '16 at 09:18
  • @simo I have edited the answer, with documentation. Try `COPY provision /provision/`. Do not use ADD (see https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#add-or-copy). – VonC Feb 20 '16 at 09:23
  • @simo I just added the chmod 755 step to be sure the script is executable in the image context. – VonC Feb 20 '16 at 09:25
  • I will try it very soon, my kids kidnapped the PC! – simo Feb 20 '16 at 09:47
  • @simo wait... are your kids doing containarization experiments with docker too? They are awesome! Ask them to test the executable bit of your script ;) – VonC Feb 20 '16 at 09:49
  • lol! Maybe if its in the Minecraft :) by the way, I am on Mac now, next to the PC, I didn't have the problem above, I just had to chmod -x provision/provision.sh – simo Feb 20 '16 at 09:51
  • 1
    @simo Well... it actually *is* in Minecraft (https://github.com/docker/dockercraft: https://github.com/docker/dockercraft/raw/master/docs/img/dockercraft.gif?raw=true) Or the Minecraft server itself is in a container (https://kitematic.com/docs/minecraft-server/) – VonC Feb 20 '16 at 09:53
  • @simo Yeap, in both cases, hours of fun for the little ones :) – VonC Feb 20 '16 at 09:58
2

In my case, the provision.sh file was a dos line ending file. I needed to re-save the file using Unix line endings.

I found those two answers very helpful to fix the problem:

RUN rm /bin/sh && ln -s /bin/bash /bin/sh 

at Using the RUN instruction in a Dockerfile with 'source' does not work

And this:

./configure : /bin/sh^M : bad interpreter

Community
  • 1
  • 1
simo
  • 23,342
  • 38
  • 121
  • 218