✦ For everyone, free.

Practical knowledge for real and everyday life

Home

9.3.4.1 Inline Environment Vars

A focused guide to Inline Environment Vars, connecting core concepts with practical Docker and container operations.

Inline environment variables are values specified directly within a Compose service's own environment field, the simplest and most directly visible way to configure a small number of runtime values without depending on a separate file or the host's own environment.

Specifying Inline Variables as a List

Each variable is listed as a KEY=value string directly within the service definition.

services:
  api:
    environment:
      - NODE_ENV=production
      - LOG_LEVEL=info
      - PORT=8080
Specifying Inline Variables as a Mapping

The same values can alternatively be expressed as a key-value mapping, a form some find more readable, particularly for values that might otherwise need careful quoting in the list form.

services:
  api:
    environment:
      NODE_ENV: production
      LOG_LEVEL: info
      PORT: "8080"

Numeric-looking values like a port number are typically quoted in this mapping form to ensure they're treated as strings, matching how an actual environment variable's value would be represented.

Why Inline Values Are Appropriate for Small, Stable Configuration

For a handful of values that rarely change and don't contain anything sensitive, inline values keep that configuration immediately visible within the Compose file itself, without the indirection of a separate referenced file.

services:
  api:
    environment:
      - TZ=UTC
When Inline Values Become Less Appropriate

As the number of variables grows substantially, or when a value is genuinely sensitive or environment-specific, inline values become less convenient than a dedicated environment file or, for sensitive values, Compose's secrets mechanism.

services:
  api:
    env_file:
      - .env.api
Why Inline Environment Variables Matter

Inline values remain a simple, immediately visible option well suited to a small set of stable, non-sensitive configuration values, complementing the other available mechanisms for situations where a more substantial or more carefully handled approach is warranted instead.