.env · transform🔒 100% client-side — never leaves your browser

ENV to Docker Compose, Dockerfile and Kubernetes Secret

Convert a .env file to Docker Compose environment variables, Dockerfile ENV lines or a Kubernetes Secret: this ENV to Docker converter quotes and escapes every value so true, $ and # survive, and runs entirely in your browser.

By Aliniyaz Mamat · last reviewed

Be the first to rate
services:
  app:
    environment:
      DATABASE_URL: "postgres://user:pass@db:5432/app"
      PORT: "3000"
      NODE_ENV: "production"
      JWT_SECRET: "xxxxxxx"

Key takeaways

  • ✓Compose output: every value is a double-quoted YAML string, because Compose rejects unquoted booleans like DEBUG: true.
  • ✓A $ becomes $$ in Compose output; otherwise Compose would try to substitute $word from your shell.
  • ✓Dockerfile ENV values are stored in the image and visible with docker history. Only use them for non-secret settings.
  • ✓Kubernetes Secret values are base64-encoded, not encrypted. Anyone who can read the Secret can decode them.
  • ✓Often the simplest option is no conversion at all: env_file: .env in Compose or docker run --env-file .env.

What it does

  • ▸docker-compose environment: block with safe YAML quoting
  • ▸Dockerfile ENV lines with escaping for $, quotes and backslashes
  • ▸Kubernetes Secret manifest with base64 (UTF-8) values
  • ▸Escapes $ as $$ to stop Compose interpolation
  • ▸Copy or download, 100% client-side

Privacy

Runs 100% in your browser. Your .env never touches our servers.

client-side only

Usage examples

Case 1 · Compose: booleans and $ handled
DEBUG=true
DB_PASSWORD=pa$word#1
services:
  app:
    environment:
      DEBUG: "true"
      DB_PASSWORD: "pa$$word#1"
Case 2 · Dockerfile ENV
NODE_ENV=production
APP_NAME=My App
# ENV values are stored in the image layers (visible with docker history).
# Use this only for non-secret settings; pass secrets at runtime.
ENV NODE_ENV=production
ENV APP_NAME="My App"
Case 3 · Kubernetes Secret
API_KEY=abc123
apiVersion: v1
kind: Secret
metadata:
  name: app-env
type: Opaque
data:
  API_KEY: YWJjMTIz

When to use this tool

  • →Moving an app from npm run dev with a .env to a compose.yaml
  • →Creating a first Kubernetes Secret from a working .env
  • →Pinning non-secret defaults (NODE_ENV, PORT) into a Dockerfile
  • →Reviewing which variables a container really gets before a deploy

Common mistakes

  • ⚠Putting passwords or API keys into Dockerfile ENV or ARG: they end up in the image layers
  • ⚠Committing the generated Kubernetes Secret YAML to git. Use Sealed Secrets, SOPS or External Secrets for git-managed clusters
  • ⚠Expecting env_file: to fill ${VAR} placeholders in compose.yaml. That is the project .env next to the file, a different mechanism
  • ⚠Editing values in the YAML by hand and forgetting the quotes: ENABLED: yes is a boolean to YAML

Four ways to get a .env into a container

MethodWhere values liveSecrets OK?Best for
env_file: .env (Compose)the .env on the hostyes, if .env is not committedlocal dev, single servers
environment: block (Compose)compose.yamlno, if compose.yaml is in gitnon-secret defaults
docker run --env-file .envthe .env on the hostyesone-off containers, CI
Dockerfile ENVthe image itselfnodefaults baked into the image
Kubernetes Secret + envFrometcd (base64)yes, with RBAC and encryption at restclusters

This converter produces the environment:, ENV and Secret variants. For the common local setup, reference the file instead and keep it out of git, see how to hide .env from git.

Quoting rules that break Docker setups

  • YAML booleans: true, false, yes, no, on, off unquoted are booleans; Compose refuses them in environment:. Quoted they are strings.
  • Interpolation: Compose replaces $VAR and ${VAR} in compose.yaml with values from your shell or the project .env. Write $$ for a literal dollar sign.
  • Dockerfile ENV: also substitutes $VAR; escape it as \$. Values with spaces need double quotes.
  • `docker run --env-file`: takes everything after = literally, quotes included. KEY="x" gives the value "x" with the quotes.

If you are not sure what a loader will make of your file, run it through the .env validator first. For multi-framework compose stacks, the Docker .env generator has a full example.

Creating the Kubernetes Secret from the command line

# straight from the .env, without writing YAML yourself
kubectl create secret generic app-env --from-env-file=.env

# or render YAML for review / GitOps (then seal or encrypt it)
kubectl create secret generic app-env --from-env-file=.env \
  --dry-run=client -o yaml > app-env.yaml
deployment.yaml (excerpt)
containers:
  - name: app
    envFrom:
      - secretRef:
          name: app-env

Pods read environment variables only at start. After changing the Secret, run kubectl rollout restart deployment/app. The comparison .env vs Kubernetes Secrets covers when each approach fits.

Frequently asked questions

Which output formats are supported?

A docker-compose environment: block, Dockerfile ENV lines and a Kubernetes Secret manifest. The service and Secret name come from the name field.

Why are all Compose values quoted?

Quoting every value as a string is the only way to be safe in YAML: true, on, 3.10 or a value starting with * would otherwise be read as booleans, numbers or YAML syntax.

Are values visible in the image when I use Dockerfile ENV?

Yes. ENV values are part of the image config and show up in docker inspect and docker history. Pass secrets at runtime with --env-file, Compose env_file or your orchestrator's secrets.

Is a Kubernetes Secret encrypted?

No, only base64-encoded. Enable encryption at rest for etcd, restrict get and list on Secrets with RBAC, and keep the manifests out of plain git.

Is my .env uploaded?

No. Parsing and conversion run in your browser; nothing is sent to a server.

Related tools

Learn more

Compare

coming soon

Get notified when env syncing launches

We're building a tiny tool to keep .env files in sync across teammates and environments. Leave your email — no spam, just a single launch ping.

We use your address only for this launch email. You can ask us to delete it at any time. Privacy policy