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.10becomes the number1.1. Quote it in the.env(VERSION="1.10") to keep it as text.CODE=007keeps its leading zeros and is emitted as'007'.ENABLED=yesstays 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=valuestop 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.