3

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.