← Docker learning path
Docker · Module 6 of 10

Environment variables and config

Pass settings into containers instead of baking them into images.

📖 Key ideas

  1. Configuration such as ports, URLs and modes belongs outside the image.
  2. -e KEY=value sets an environment variable for one run.
  3. --env-file .env loads many variables from a file.
  4. ENV in a Dockerfile sets defaults inside the image.
  5. Never bake passwords into an image; inject secrets at runtime.
💡 Real-life example: Same phone, different SIM card: the image stays the same, the settings change per place.
-eSets one environment variable
--env-fileLoads variables from a file
ENVDefault variable inside the image
SecretSensitive value injected at runtime