Docker Compose Formatter Online

Beautify or minify Docker Compose YAML files instantly in your browser.

Indent:
INPUT0 chars
OUTPUT

When a Docker Compose formatter is the right tool

Use this page to beautify or minify a docker-compose.yml (or any other single YAML document) in the browser. The output updates as you type. It does not check that the file is valid Compose, and it does not upgrade a Compose version key.

If you are starting from a docker run command instead, use Docker Run to Compose. For generic YAML, YAML Formatter uses the same js-yaml engine.

Use cases

Cleaning up indentation

Leave the mode on Beautify and pick 2- or 4-space indent. Load Sample is a short Compose-like file with a version: '3.8' key, two services, a network, and a volume.

Making a compact dump

Minify is not just “fewer blank lines.” It dumps collections in YAML flow style, so the sample becomes one long {version: '3.8', services: {…}} line. That is valid YAML, but it is not the usual block-style Compose file.

How formatting works

The input is loaded with yaml.load and written back with yaml.dump. Key order is kept. After a dump, empty nodes often show as null, double quotes may become single quotes, and comments disappear.

Example — Beautify (2-space) output of the built-in sample
version: '3.8'
services:
  web:
    image: nginx:alpine
    ports:
      - '80:80'
    environment:
      - NGINX_HOST=example.com
    depends_on:
      - api
  api:
    build:
      context: ./api
      dockerfile: Dockerfile
    ports:
      - '3000:3000'
networks:
  frontend: null
volumes:
  postgres_data: null

The sample’s # a comment line is gone, and the empty networks.frontend / volumes.postgres_data mappings are written as null.

What this tool does not do

It does not validate services, ports, or Compose versions, keep comments, or accept a multi-document YAML stream. Formatting stays in your browser.

How to use Docker Compose Formatter

  1. Choose Beautify (2 or 4 spaces) or Minify.
  2. Paste a Compose file, or use Load Sample, and read the live output.
  3. Copy when the result looks right. Clear resets both sides.

Frequently asked questions

How does Docker Compose Formatter work?

It is a YAML pretty-printer, not a Compose schema or version validator. js-yaml loads the input and dumps it again. Beautify uses indent 2 or 4, a 120-character preferred line width, noRefs, and does not sort keys. Minify dumps with flow-style collections (flowLevel 0) and collapses extra blank lines, which usually produces a single compact line. The result updates as you type.

Does this support every Docker Compose version?

The formatter does not check a Compose version or schema. Any single YAML document will format, including YAML that is not a Compose file. Empty mappings such as networks: frontend: are rewritten as frontend: null. A file with more than one YAML document is rejected.

Are comments and types preserved?

Comments are dropped on a round trip, including the sample’s inline comment. js-yaml may also change quoting, and values that look like dates can become ISO timestamps. That is the same family of quirks as YAML Formatter on this site.

Is my docker-compose.yml uploaded?

No. Formatting runs in your browser. Closing the tab discards what you pasted. Load Sample pastes a short Compose-like document and Clear empties both sides.

Related tools and guides

References

  • Parsing and dumping use js-yaml. Compose keywords are treated as ordinary YAML keys.
  • For the Compose file format itself, see the Docker Compose file reference. This page does not validate against that schema.