Ad space (banner)
AD

Got the fundamentals? A structured Docker course is a fast way to level up.

Find Docker courses on Udemy

Affiliate link. Costs you nothing extra.

🐳Docker Lessons
Lesson 18 / 45

Passing Environment Variables with docker run -e

When a container needs configuration — a database password, a mode flag — use -e. It passes an environment variable into the container.

The syntax is docker run -e KEY=VALUE image. Repeat -e for each variable you need.

Running docker run -e ENV=production nginx starts the container with ENV set to production, which the application inside can read.

A common stumble is writing secrets directly into a Dockerfile or a command you commit to version control. Passwords belong in environment variables or a secret manager, never baked into the image.

In real work, environment variables are how the same image serves development, staging and production without change.

Docker
Try it (type this into the pseudo terminal)
docker run -e ENV=production nginx

🧑‍💻 You can type this command into the Docker pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)