SHELL instruction over repeating pwsh or powershell wrappers in RUN.
| Property | Value |
|---|---|
| Severity | Style |
| Category | Style |
| Default | Enabled (experimental) |
| Auto-fix | Yes (--fix --fix-unsafe) |
Description
This rule detects repeated shell-formRUN instructions that invoke PowerShell explicitly, for example:
RUN pwsh -Command ...RUN powershell -Command ...RUN @powershell -Command ...
SHELL [...] instruction, the rule does nothing.
The recommendation applies on both Windows and Linux. A Linux image such as mcr.microsoft.com/powershell:ubuntu-22.04 still benefits from
switching to a PowerShell SHELL once multiple PowerShell RUN commands appear.
Why this matters
Repeating the full wrapper on everyRUN line adds noise and makes PowerShell-specific defaults easy to forget. A dedicated SHELL instruction:
- makes repeated PowerShell build steps easier to read
- centralizes the shell choice instead of duplicating it across
RUNs - lets tally inject sane build defaults once:
$ErrorActionPreference = 'Stop'$PSNativeCommandUseErrorActionPreference = $true$ProgressPreference = 'SilentlyContinue'
Examples
Before (violation)
After (fixed with --fix --fix-unsafe)
Windows example
Configuration
This rule has no rule-specific options today.Fix behavior
The fixer is intentionally conservative. It only rewrites repeated PowerShell wrappers when the repeatedRUN instructions share the same executable
and the same arguments before -Command (for example, repeated pwsh -NoProfile -Command ...).
On Windows container stages, the fixer also collaborates with tally/prefer-run-heredoc:
- it can qualify bare
RUN powershell ...chains, not only explicit-Commandwrappers - when a
cmdstage is converted to a PowerShellSHELL, later PowerShell-safeRUNinstructions can stay under that shell instead of forcing an immediate restore tocmd - after that rewrite,
tally/prefer-run-heredoccan merge the resulting PowerShellRUNsequence into a PowerShell heredoc in the same fix pass