Docker
/Intermediate
ENV Variables
Definition
The instruction used to set environment variables inside the Docker image. These variables persist in the final image and are available to the application running inside the container.
Explain Like I'm New
Leaving sticky notes for your app to read later. You write a sticky note: `DATABASE_PORT=5432`. When the app boots up days later, it reads the note to know where to connect.
Real World Example
Setting `ENV NODE_ENV=production`. This permanently embeds the environment variable into the image. When Node.js boots up, it reads this variable and automatically switches to high-performance production mode.
Common Use Cases
- •Configuration
- •Path management
Interview Questions
basic
- Can a user change an `ENV` variable when starting the live container, or is it permanently frozen in the image?
intermediate
- Why is it a severe security risk to use the `ENV` instruction to store database passwords in a Dockerfile?