Changing the default shell with RUN

Use the SHELL instruction to explicitly select the Dockerfile’s default shell.

Description

SHELL selects the interpreter for subsequent shell-form RUN, CMD, and ENTRYPOINT instructions in the stage.

Potential impact

Replacing /bin/sh with a symlink to Bash also changes the interpreter for other scripts that call /bin/sh.

Remediation

If later instructions need Bash, confirm the image contains /bin/bash, then declare SHELL ["/bin/bash", "-c"] before them. The user’s login shell is configured separately.

Examples

Before

dockerfile
RUN ln -sfv /bin/bash /bin/sh

After

dockerfile
SHELL ["/bin/bash", "-c"]

References