Build once, configure everywhere
The same image should run in development, staging and production — only the configuration changes. The twelve-factor app rule: keep config in the environment. Compose reads it from env_files and interpolates ${VARIABLES} from your shell.
env_file and ${VAR:-default}
services:
api:
build: .
ports:
- "3000:3000"
env_file:
- .env.production
environment:
APP_VERSION: ${APP_VERSION:-dev}