Docker Compose Files and YAML Patterns/Environment as key/value map

Provide container environment values inline in YAML.

Section: Environment Variables and Env Files

Environment as key/value map

yaml
yaml
services:
  api:
    image: myapi:latest
    environment:
      NODE_ENV: development
      PORT: "3000"
Explanation

Use strings for values that might be parsed unexpectedly.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Environment Variables and Env Files
Environment as list
Alternative environment syntax using `KEY=value` entries.
OpenIn sheetyamlsame section
Load variables from env file
Loads container environment variables from one or more files.
OpenIn sheetyamlsame section
Interpolate variables into compose file
Uses shell-style variable interpolation inside the Compose file.
OpenIn sheetyamlsame section
Pass env file at runtime
Uses a specific env file when rendering the Compose project.
OpenIn sheetbashsame section
Minimal web + db stack
Simple two-service stack with port publishing and environment variables.
OpenIn sheetyaml2 tag match
Define optional profiles
Marks a service as optional unless its profile is enabled.
OpenIn sheetyaml2 tag match