Jimmy Adaro
Jimmy Adaro

Reputation: 1405

bash does not work using Docker's SHELL instruction

I need to use bash in the scripts of a CI/CD pipeline, so I'm trying with this simple image:

FROM alpine:3.4
RUN apk update -q && apk add --no-cache bash -q
SHELL ["/bin/bash", "--login", "-c"]
RUN echo $0

What I get in my terminal is this:

$ docker build .
    Sending build context to Docker daemon  2.048kB
    Step 1/4 : FROM alpine:3.4
     ---> b7c5ffe56db7
    Step 2/4 : RUN apk update -q && apk add --no-cache bash -q
     ---> Using cache
     ---> 18b729da453c
    Step 3/4 : SHELL ["/bin/bash", "--login", "-c"]
     ---> Using cache
     ---> 03ca0df4a543
    Step 4/4 : RUN echo $0
     ---> Running in a65419dafc4b
    /bin/bash
    Removing intermediate container a65419dafc4b
     ---> 2963f9e0e563
    Successfully built 2963f9e0e563

After that, I run that container and get this:

$ docker run -it 2963f9e0e563
/ $ echo $0
/bin/sh
/ $ 

(it runs as root but I changed "#" with "$" for this post)

Why is it using sh instead of bash?

Upvotes: 3

Views: 1800

Answers (1)

Alassane Ndiaye
Alassane Ndiaye

Reputation: 4767

The SHELL command only modifies the shell that is used to execute the instructions inside the Dockerfile.

If you want to change the shell that's used for the container runtime, you can add CMD ["/bin/bash"] to your Dockerfile in order to change the container default executable to /bin/bash. You could also specify the executable from the command line using docker run -it <image> /bin/bash.

Upvotes: 3

Related Questions