5

So I can't seem to figure this out, but I'm getting error code 127 when running a Dockerfile. What causes this error?

My Dockerfile:

FROM composer as comp

FROM php:7.4-fpm-alpine
COPY --from=comp /usr/bin/composer /usr/bin/composer
COPY ./docker/install-deps.sh /tmp/install-deps.sh
RUN echo $(ls /tmp)
RUN /tmp/install-deps.sh
COPY . /var/www
WORKDIR /var/www
RUN composer install -o --no-dev

The results after building the Dockerfile:

Building php
Step 1/9 : FROM composer as comp
 ---> 433420023b60
Step 2/9 : FROM php:7.4-fpm-alpine
 ---> 78e945602ecc
Step 3/9 : COPY --from=comp /usr/bin/composer /usr/bin/composer
 ---> 46117e22b4de
Step 4/9 : COPY ./docker/install-deps.sh /tmp/install-deps.sh
 ---> 7e46a2ee759c
Step 5/9 : RUN echo $(ls /tmp)
 ---> Running in aa1f900032f9
install-deps.sh
Removing intermediate container aa1f900032f9
 ---> eb455e78b7f6
Step 6/9 : RUN /tmp/install-deps.sh
 ---> Running in 6402a15cccb2
/bin/sh: /tmp/install-deps.sh: not found
ERROR: Service 'php' failed to build: The command '/bin/sh -c /tmp/install-deps.sh' returned a non-zero code: 127

The install-deps.sh:

#!/bin/sh

set -e

apk add --update --no-cache \
    postgresql-dev \
    mysql-client \
    yaml-dev \
    git \
    openssl

docker-php-ext-install pcntl pdo_mysql pdo_pgsql

# yaml
apk add --no-cache --virtual .build-deps g++ make autoconf
pecl channel-update pecl.php.net
pecl install yaml
docker-php-ext-enable yaml
apk del --purge .build-deps
Sean Ziegler
  • 123
  • 5
Tyler
  • 3,713
  • 6
  • 37
  • 63
  • Can you try `RUN sh /tmp/install-deps.sh ` – nischay goyal Jun 15 '20 at 15:25
  • Is the script file executable? Why `echo $(...)` instead of just running the command directly? (`RUN ls -l /tmp/install-deps.sh` without the `echo` wrapper.) – David Maze Jun 15 '20 at 15:26
  • Running it with the `sh` gave an `illegal option` error. Yes, it is executable, and I use the echo because I tried just an ls and I wasn't seeing the results when I ran `docker-compose build --no-cache` – Tyler Jun 16 '20 at 10:12

1 Answers1

6

Docker is executing the install-deps.sh script. The issue is with a command inside install-deps.sh that is not recognized when docker attempts to run the script.

As you can see the script returns an error code of 127 meaning that a command within the file does not exist.

For instance - try this:

touch test.sh
echo "not-a-command" >> test.sh
chmod 755 test.sh
/bin/sh -c "./test.sh"

Output:

/root/test.sh: line 1: not-a-command: command not found

Now check the exit code:

echo $?
127

I would suggest running the script inside an interactive environment to identify/install the command that is not found.

Sean Ziegler
  • 123
  • 5
  • 1
    Yeah, you are right, if I make the file blank it works. I think it has something to do with the `#!/bin/sh`. I should be able to figure it out from here, when I find out what it is I'll comment on this question and then mark it as correct, thanks! – Tyler Jun 16 '20 at 10:17
  • 1
    Is there any nice way of getting docker to spit out the output of the shell script it's trying to execute to make debugging a little easier? – stevec Oct 31 '22 at 15:27