Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent the `#!/bin/bash: not found` error when calling a script from Dockerfile

i have the following Dockerfile:

FROM debian:stretch-backports

MAINTAINER c33s

ARG DEBIAN_FRONTEND=noninteractive
COPY provision-base.sh /root/provision-base.sh
RUN chmod +x /root/provision-base.sh && /root/provision-base.sh

why do i get the following error running it:

...snip...
/root/provision-base.sh: 1: /root/provision-base.sh: #!/bin/bash: not found
...snip...
  • the file exists RUN ls /root/provision-base.sh shows it
  • RUN which bash also shows that bash is installed
  • the script gets started and continues after the error
  • the build succeeds

build log on dockerhub:https://hub.docker.com/r/c33s/debian/builds/bd6g8cqr2rtys9a2gguehcw/ (snip of the build log also on pastebin https://pastebin.com/6x1UK53H)

like image 448
c33s Avatar asked Oct 25 '25 16:10

c33s


1 Answers

Bash is often in different places on different systems. Often at /bin/bash, but on this container it's located here:

 % docker run -it debian:stretch-backports
root@bb01a3db779e:/# type bash
bash is /usr/bin/bash

The env command is more predictable, and can be used to locate other programs in the shebang line. So try this in your script:

#!/usr/bin/env bash
like image 144
Harald Nordgren Avatar answered Oct 28 '25 07:10

Harald Nordgren