8

I have Dockerfile containing:

FROM alpine

COPY script.sh /script.sh

CMD ["./script.sh"]

and a script.sh (with executable permission):

#!/bin/bash
echo "hello world from script file"

when I run

docker run --name testing fff0e5c81ca0

where fff0e5c81ca0 is the id after building, I get an error

standard_init_linux.go:195: exec user process caused "no such file or directory"

So how can I solve it?

Shahriar
  • 13,460
  • 8
  • 78
  • 95
Mumbaikar007
  • 441
  • 1
  • 6
  • 16
  • 1
    Did you try `CMD ["sh /script.sh"]`? – Maroun Feb 03 '18 at 12:13
  • I can't make it works `CMD ["sh /script.sh"]` – Shahriar Feb 03 '18 at 12:37
  • In alpine, ENTRYPOINT is already `/bin/sh`. – Shahriar Feb 03 '18 at 12:38
  • I got it. Do you want to add answer? Or I will update my answer @Maroun – Shahriar Feb 03 '18 at 12:42
  • I got this ... docker: Error response from daemon: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"sh /script.sh\": stat sh /script.sh: no such file or directory": unknown. ERRO[0002] error waiting for container: context canceled – Mumbaikar007 Feb 03 '18 at 12:48
  • Possible duplicate of [How to run a bash script in an Alpine Docker container](https://stackoverflow.com/questions/44803982/how-to-run-a-bash-script-in-an-alpine-docker-container) – Joe Feb 03 '18 at 14:10

2 Answers2

17

To run a bash script in alpine based image, you need to do either one

  1. Install bash

    $ RUN apk add --update bash
    
  2. Use #!/bin/sh in script instead of #!/bin/bash

You need to do any one of these two or both

Or, like @Maroun's answer in comment, you can change your CMD to execute your bash script

CMD ["sh", "./script.sh"]
Shahriar
  • 13,460
  • 8
  • 78
  • 95
1

Your Dockerfile may look like this:

FROM openjdk:8u171-jre-alpine3.8
COPY script.sh /script.sh
CMD ["sh", "./script.sh"]
yuen26
  • 871
  • 11
  • 12
  • FROM alpine:3.6 RUN apk --no-cache add curl bash RUN apk add --no-cache tzdata RUN apk add --update bash RUN mkdir -p /var/log/cron \ && touch /var/log/cron/cron.log \ && mkdir -m 0644 -p /etc/cron.d COPY run.sh /usr/share/run.sh ADD curlurl /etc/crontabs/sit/ ADD curlurl2 /etc/crontabs/uat/ RUN chmod +x /usr/share/run.sh CMD bash -c "crond -L /var/log/cron/cron.log && tail -F /var/log/cron/cron.log" WORKDIR /usr/share/ #CMD ["sh", "./run.sh"] in run.sh (#!/bin/bash cp -f /etc/crontabs/sit/curlurl /etc/crontabs/root) but getting error as file not found. – Baharul Dec 12 '19 at 16:32