Compose environment file and secrets
A Compose environment file supplies configuration values that Compose interpolates into service definitions without hardcoding actual credentials in the Compose YAML. In this course, the uncommitted .env file holds local deployment values, while a committed .env.example documents variable names using fake values. Secrets must never be baked into Docker image layers because image inspection and history can expose them.
Minimal example
services:
mysql:
image: mysql:8.4
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}Learn this concept
Lesson 7.1 · Multi-stage Dockerfiles for GoUsed in exercises
Exercise 7.2 · Production container stack Exercise 7.16 · Filesystem secret scannerPrerequisite conceptsDocker Compose