FormatterHQ

.env to YAML Converter

Paste a dotenv file and get YAML key: value pairs, ready for a Docker Compose environment block, a Kubernetes ConfigMap or a CI variables file. Optionally nest keys on a separator.

Input SHELL
Output YAML
Ready.

How to use the .env to YAML Converter

  1. Paste your .env contents into the input editor.
  2. Keep Convert numbers & booleans on for native YAML types, or turn it off to quote every value.
  3. Tick Nest keys and set the Nesting separator (default __) to build a YAML tree.
  4. Click Convert and paste the YAML where you need it.

Turn dotenv files into YAML with the env to YAML converter

The env to YAML converter reads a .env file with a full dotenv parser (comments, quotes, export, multi-line values and ${VAR} expansion) and writes the result as YAML. Most YAML-based tools, including Docker Compose, Kubernetes ConfigMaps, GitHub Actions and Helm values files, can take the output with little or no editing.

Example

A Postgres container's .env:

POSTGRES_USER=app
POSTGRES_PASSWORD="s3cr#t"
POSTGRES_PORT=5432
PGDATA=/var/lib/postgresql/data
ENABLE_SSL=true

Converted YAML:

POSTGRES_USER: app
POSTGRES_PASSWORD: s3cr#t
POSTGRES_PORT: 5432
PGDATA: /var/lib/postgresql/data
ENABLE_SSL: true

Indent it under environment: in docker-compose.yml, or under data: in a ConfigMap. Note that the # in the password needs no quoting in YAML because it is not preceded by a space.

Nesting keys

Tick Nest keys to split variable names on the separator. With __:

MAIL__HOST=smtp.example.com
MAIL__PORT=587
APP_ENV=staging

becomes

MAIL:
  HOST: smtp.example.com
  PORT: 587
APP_ENV: staging

Single underscores are left alone, so APP_ENV stays one key. This suits Helm values files and Spring or .NET configuration, which expect a tree.

Typed values vs. strings

With Convert numbers & booleans on, unquoted numbers and true/false become native YAML scalars. Watch for these cases:

  • VERSION=1.10 becomes the number 1.1. Quote it in the .env (VERSION="1.10") to keep it as text.
  • CODE=007 keeps its leading zeros and is emitted as '007'.
  • ENABLED=yes stays a string but is written as 'yes', so YAML 1.1 parsers do not read it as a boolean.

Kubernetes ConfigMap data and Compose environment values must be strings. For those targets, turn the option off and every value is quoted: PORT: '80', ENABLED: 'true'.

Dollar signs in Docker Compose

Compose performs its own variable substitution on the YAML file, so a literal $ in a value, as in a password like pa$word, is treated as the start of a variable and silently replaced with an empty string. Write it as $$ inside docker-compose.yml to keep the character. This only affects values you paste into the Compose file; variables loaded with env_file: .env are passed through as written. If you do not need the values inside the Compose file itself, env_file is often the simpler choice, and for Kubernetes, kubectl create configmap app-env --from-env-file=.env builds the ConfigMap directly.

Edge cases

  • Multi-line quoted values, such as certificates, are written as YAML block or quoted strings with the line breaks preserved.
  • ${VAR} references are resolved from keys defined earlier in the file before conversion, so the YAML contains final values.
  • Lines that are not KEY=value stop the conversion with the line number, so nothing is silently skipped.

Need JSON instead? Use .env to JSON. To check or reformat the result, paste it into the YAML validator. Converting whole docker run commands? Try docker run to Docker Compose.

Privacy

Your .env file, and the secrets in it, never leave the browser; parsing and YAML output happen locally.

Frequently asked questions

How do I use the output in docker-compose.yml?
Paste the YAML under a service's environment: key and indent it one level. For values Compose must treat as text, such as true or 5432, turn off Convert numbers & booleans so they are quoted.
Why did 1.10 turn into 1.1?
With typed conversion on, an unquoted 1.10 is read as a number, and numbers drop trailing zeros. Quote the value in your .env file or turn off type conversion to keep it exactly.
Can I create a nested YAML structure from flat variables?
Yes. Tick Nest keys and set the separator, usually __. DB__HOST and DB__PORT then become a DB mapping with HOST and PORT inside.
Are comments from the .env file kept?
No. Comments are removed during parsing, because the output is generated from the parsed values. Add any comments you need to the YAML afterward.

Last updated September 26, 2026

Guides

Related tools