Align Docker Compose Environment Variables

Align environment variable definitions in Docker Compose files for improved readability across services.

Configuration Files

Detailed Explanation

Tidying Docker Compose Environment Blocks

Docker Compose YAML files often include environment blocks with many key-value pairs. When these grow beyond a few entries, alignment makes the configuration easier to review and maintain.

Before

DB_HOST=postgres
DB_PORT=5432
DB_NAME=app
DB_USER=admin
DB_PASSWORD=secret
REDIS_URL=redis://redis:6379
JWT_SECRET=my-long-secret-key
LOG_LEVEL=debug
CORS_ORIGIN=http://localhost:3000
MAX_UPLOAD_SIZE=10485760

After

DB_HOST         =postgres
DB_PORT         =5432
DB_NAME         =app
DB_USER         =admin
DB_PASSWORD     =secret
REDIS_URL       =redis://redis:6379
JWT_SECRET      =my-long-secret-key
LOG_LEVEL       =debug
CORS_ORIGIN     =http://localhost:3000
MAX_UPLOAD_SIZE =10485760

Configuration

  1. Select Equals = as the input delimiter.
  2. Output delimiter: Same as Input.
  3. Enable Trim whitespace.
  4. Left-align both columns.

Docker Compose YAML Syntax

There are two ways to define environment variables in Docker Compose:

  1. Mapping style: KEY: value — use the Colon delimiter for these.
  2. Array style: - KEY=value — strip the leading - first, then use the Equals delimiter.

This tool works best with the second (array) style after removing the YAML list markers. For mapping style, switch to the colon delimiter.

Multiple Services

If you have many services each with their own environment block, align each block separately. The tool processes all lines as one table, so mixing entries from different services would create an overly wide alignment.

Use Case

A DevOps engineer is reviewing a Docker Compose file with 8 services and wants to align the environment blocks for each service to improve readability during code review.

Try It — Text Column Aligner

Open full tool