Key Features of the Dockerfile Formatter
- Cleans indentation, spacing and line wrapping for Dockerfiles and Containerfiles
- Normalizes multi-line RUN instructions with consistent backslashes and indentation
- Respects Dockerfile semantics – no instruction reordering, no shell logic changes
- Deterministic output: same input and version ⇒ same formatted Dockerfile
- Perfect companion for pre-commit hooks, monorepos and CI jobs using dprint
- Web-based editor with syntax highlighting, diff-friendly output and copy/download actions
- Works well with multi-stage builds, build args and typical Node/.NET/Go images
🛠️ How to Format a Dockerfile for dockerfile-formatter
1. Paste or Upload Your Dockerfile
Paste your Dockerfile into the editor or drop a Dockerfile/Containerfile from your project. Small snippets (like a single FROM/RUN block) work too if you just want to experiment.
2. Run the Formatter
Click "Format". The tool sends your source to a secure, dprint-based backend that adjusts indentation, spacing, array-style instructions and multi-line RUN chains without touching the execution logic.
3. Review, Copy or Download
Compare the formatted output with your original file. When you're satisfied, copy the result back into your repo or download the formatted Dockerfile to commit it directly.
Technical Details
Supported File Types
The formatter targets Docker build instructions and compatible container build files used across Docker, Podman and similar tools.
| Type | Example | Notes |
|---|---|---|
| Dockerfile | Dockerfile, Dockerfile.prod, Dockerfile.node18 | Classic Docker build files for images |
| Containerfile | Containerfile | Podman / Buildah style configuration files |
| Inline snippets | FROM node:18-alpine | Small fragments or examples are also supported for quick tests |
Formatting Behaviour (dprint-style)
High-level behaviours of the underlying dprint plugin used by this tool:
| Area | Behaviour | Example |
|---|---|---|
| Indentation | Normalizes indentation for continued lines in RUN and other instructions | RUN set -eux; \\n npm ci; \\n npm cache clean --force |
| Lists & arrays | Cleans spacing in JSON-style arrays for CMD/ENTRYPOINT/HEALTHCHECK | CMD ["npm", "start"] → CMD ["npm", "start"] (but with consistent spaces) |
| Spacing | Removes redundant spaces around instructions while preserving meaning | ENV NODE_ENV=production |
| Line wrapping | May reflow long RUN chains for readability without changing order | Long shell pipelines become easier to scan and review in diffs |
| Comments | Preserves full-line and inline comments beside instructions | # base image for build stage\nFROM node:18 AS build |
Non-goals
This formatter is intentionally scoped to layout, so you can combine it with other DevOps tools:
| Item | Handled? | Notes |
|---|---|---|
| Hadolint-style linting | ❌ | Use hadolint or similar tools for best-practice checks and warnings |
| Security scanning | ❌ | No CVE or vulnerability scanning of images or registries |
| Image building | ❌ | Does not execute docker build or interact with Docker Engine |
| Instruction reordering | ❌ | Never reorders instructions; only indentation and whitespace change |
| Base image hardening | ❌ | Does not recommend base images; it formats whatever you provide |
CLI & CI Equivalents
Like the result? Mirror the same behaviour locally and in CI with dprint and complementary tools.
Universal (dprint)
Initialize dprint and add Dockerfile plugin
dprint init
# In dprint.json, add:
# {
# "plugins": ["https://plugins.dprint.dev/dockerfile-0.x.wasm"]
# }
# Then format your Dockerfiles:
dprint fmt DockerfileClosest match to this online formatter, so developers and CI use the same style.
Linux/macOS
Lint with hadolint (complements formatting)
hadolint DockerfileCombine formatting (style) with linting (best practices, smaller images, healthchecks).
Git / pre-commit
Run dprint on changed Dockerfiles before commit
# .pre-commit-config.yaml (conceptual)
- repo: local
hooks:
- id: dprint-dockerfile
name: dprint Dockerfiles
entry: dprint fmt
language: system
files: "(Dockerfile|Containerfile)$"Guarantees that every Dockerfile merged to main is already formatted.
Common Use Cases
Dev & Platform Engineering
- Normalize Dockerfiles across microservices before code review
- Clean up legacy Dockerfiles inherited from multiple teams or templates
- Standardize style when migrating images, base OS versions or build strategies
# Typical multi-stage Dockerfile (clean, review-friendly)\nFROM node:18 AS build\nWORKDIR /app\nCOPY package*.json ./\nRUN npm ci && npm cache clean --force\nCOPY . .\nRUN npm run build\n\nFROM node:18-alpine\nWORKDIR /app\nCOPY --from=build /app/dist ./\nCMD ["node", "index.js"]CI/CD Pipelines
- Fail builds when Dockerfiles are not properly formatted
- Auto-fix style on feature branches via pre-commit hooks or CI jobs
- Keep Docker configuration readable in long-lived monorepos and platform repos
# Example Git pre-commit hook (pseudo-code)\n#!/bin/sh\nchanged=$(git diff --cached --name-only --diff-filter=ACM | grep -E 'Dockerfile|Containerfile' || true)\n[ -z "$changed" ] && exit 0\ndprint fmt $changed\ngit add $changedTeam Onboarding & Consistency
- Give new team members a single, opinionated Dockerfile style to follow
- Remove code-style debates from PRs: let the formatter be the source of truth
- Align local formatting, repo hooks and CI jobs around the same dprint config
# Example snippet for docs/onboarding.md\n1. Install dprint locally\n2. Copy the shared dprint.json from the platform repo\n3. Run `dprint fmt Dockerfile` before opening a pull request❓ Frequently Asked Questions
Does formatting change how my image builds?
Is this the same as linting with hadolint?
Can I enforce this style in CI?
Does it support multi-stage builds?
Is my Dockerfile uploaded to a server?
Pro Tips
Run formatting automatically in CI so Dockerfile style never drifts between services or teams.
Pair this formatter with a linter like hadolint to cover both layout and best-practice guidance.
Agree on a standard multi-stage Dockerfile template early in a project and keep it formatted so new services follow the same structure.
If you work in a monorepo, share a single dprint configuration so application code, infra code and Dockerfiles use consistent conventions.
Additional Resources
Other Tools
- CSS Beautifier
- HTML Beautifier
- Javascript Beautifier
- PHP Beautifier
- Color Picker
- Sprite Extractor
- Base64 Decoder
- Base64 Encoder
- Csharp Formatter
- Csv Formatter
- Elm Formatter
- ENV Formatter
- Go Formatter
- Graphql Formatter
- Hcl Formatter
- INI Formatter
- JSON Formatter
- Latex Formatter
- Markdown Formatter
- Objectivec Formatter
- Php Formatter
- Proto Formatter
- Python Formatter
- Ruby Formatter
- Rust Formatter
- Scala Formatter
- Shell Script Formatter
- SQL Formatter
- SVG Formatter
- Swift Formatter
- TOML Formatter
- Typescript Formatter
- XML Formatter
- YAML Formatter
- Yarn Formatter
- CSS Minifier
- Html Minifier
- Javascript Minifier
- JSON Minifier
- XML Minifier
- Http Headers Viewer
- PDF To Text
- Regex Tester
- Serp Rank Checker
- Whois Lookup