.env · generator · Docker Compose

Docker Compose .env Generator

docker-compose auto-loads a .env file from the same directory as the compose file. Variables can be referenced in compose.yml as ${VAR}. This generator produces a compose-idiomatic .env.

.env for Docker Compose · 8 keys
Customize →
COMPOSE_PROJECT_NAME=myapp
POSTGRES_USER=app
POSTGRES_PASSWORD=vBqPErvyXQzg1FJ7n1FJjJMZpNJGq3HA1b2USoazmZ3O3ghG
POSTGRES_DB=app
POSTGRES_PORT=5432
REDIS_PORT=6379
APP_PORT=3000
NODE_ENV=production

Secrets regenerate on every page load. Want to combine stacks (e.g., Next.js + Stripe + Supabase)? Use the full generator.

How to use this .env in Docker Compose

  1. 1.Save as .env next to your docker-compose.yml.
  2. 2.Reference in compose.yml with ${POSTGRES_PASSWORD} syntax.
  3. 3.Run docker compose config to preview the resolved YAML before starting containers.
  4. 4.In prod, use docker secrets or your host's env injection instead of committing a compose .env.

Gotchas

  • The compose .env is different from the .env passed via env_file: — the former is for substitution, the latter is injected into the container.
  • Multi-line values break compose substitution. Keep each value on one line.
  • ${VAR:-default} gives a fallback; ${VAR:?err} fails the build if unset. Use the error form for required vars.

Common keys explained

COMPOSE_PROJECT_NAME

Prefix for container names. Avoids collisions across projects.

POSTGRES_USER

Passed to the official postgres image. Bootstraps the DB user.

POSTGRES_PASSWORD

Set to a generated value — weak passwords get brute-forced.

POSTGRES_DB

Default database created on first boot.

APP_PORT

Host port for the app service. Referenced as ${APP_PORT}:3000 in compose.

Related tools

Other stacks