Skip to contents

Adds a SHELL instruction to override the default shell used for commands.

Usage

dfi_shell(dockerfile, shell)

Arguments

dockerfile

A dockerfile object

shell

Shell command and parameters (character vector or string)

Value

An updated dockerfile object with the SHELL instruction added

Details

The SHELL instruction allows overriding the default shell used for the shell form of commands. The default shell on Linux is ["/bin/sh", "-c"], and on Windows is ["cmd", "/S", "/C"].

This instruction is particularly useful for:

  • Using bash-specific features

  • Enabling better error handling with options like -e (exit on error)

  • Setting up pipefail to catch errors in pipelines

The function automatically converts the shell command to JSON array format if provided as a vector.

See also

dfi_run() for executing commands with the shell & Official Docker SHELL documentation

Other dockerfile instruction functions: dfi_add(), dfi_arg(), dfi_cmd(), dfi_copy(), dfi_entrypoint(), dfi_env(), dfi_expose(), dfi_from(), dfi_healthcheck(), dfi_label(), dfi_maintainer(), dfi_onbuild(), dfi_run(), dfi_stopsignal(), dfi_user(), dfi_volume(), dfi_workdir()

Examples

# Set shell to bash with expanded error messaging
df <- dockerfile() |>
  dfi_from("rocker/r-ver:4.4.0") |>
  dfi_shell(c("/bin/bash", "-e", "-o", "pipefail", "-c"))
df
#> FROM rocker/r-ver:4.4.0
#> SHELL ["/bin/bash","-e","-o","pipefail","-c"]