DockerPlay
🎖️
3d
Chapter 0412 mins • beginner

Mastering `docker run` Flags

Environment Variables, Auto-removal, Restart Policies & Memory Limits

What You Will Master:

  • Inject configuration using `-e KEY=VALUE`
  • Configure automatic restarts with `--restart always`
  • Set container resource boundaries with `--memory` and `--cpus`

1Essential docker run Flags

  • -e / --env: Passes environment variables into the container runtime.
  • --restart: Defines auto-restart behavior on crash (always, on-failure, unless-stopped).
  • --rm: Automatically deletes container when its process exits (great for one-off CLI tools or tests).
  • --memory: Enforces hard RAM limits (e.g. --memory=512m).
Interactive Lab

Configure Environment & Restart Policy

Run a node container with custom environment variable `APP_ENV=production` and restart policy `always`.

0/1 Steps
Step 1: Run node container with APP_ENV=production and --restart always

Run `docker run -d --name my-api -e APP_ENV=production --restart always node:22-alpine`

Chapter Knowledge Quiz

Pass the 3-question assessment to earn +50 XP and complete this chapter.

Sponsor & Resources