Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a bash script from alpine based docker

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?

like image 800
Mumbaikar007 Avatar asked Feb 03 '18 12:02

Mumbaikar007


People also ask

Does Alpine Docker have bash?

By default, bash is not included with BusyBox and Alpine Linux. The postmarketOS project, which is designed to run on mobile devices, is based on Alpine Linux. Many Docker images are also based upon Alpine, and you may install bash shell in Docker-based images too.

Does Alpine have shell?

There is no Bash installed by default; Alpine uses BusyBox Bash as the default shell.

What shell does alpine use?

Note: By default Alpine Linux uses the ash shell, but many users may prefer bash, zsh, fish or another shell.


1 Answers

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"]
like image 130
Shahriar Avatar answered Oct 08 '22 13:10

Shahriar