← Docker learning pathDocker · Module 6 of 10
Environment variables and config
Pass settings into containers instead of baking them into images.
📖 Key ideas
- Configuration such as ports, URLs and modes belongs outside the image.
- -e KEY=value sets an environment variable for one run.
- --env-file .env loads many variables from a file.
- ENV in a Dockerfile sets defaults inside the image.
- 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