Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
Docker Docker & Containers: From Zero to Production Docker Containers Module 3 — Working with Containers

Running Containers — Ports, Volumes, and Environment Variables

Reviewed & accurate
AI Summary

What You'll Learn

Beginner

  • How to publish ports (-p)
  • How to mount volumes (-v)
  • How to set environment variables (-e)
Terminalbash
# Port mapping
docker run -d -p 8080:80 nginx

# Environment variables
docker run -e DB_HOST=db -e DB_PORT=5432 myapp

# Volume
docker run -v /host/path:/container/path nginx

# Named container
docker run -d --name my-web nginx
FlagPurpose
-dDetached (background)
-itInteractive terminal
-pPort mapping
-eEnvironment variable
-vVolume mount
--nameContainer name

Practical Exercise

Run nginx with port mapping
Run with environment variables
Run with a volume mount

Key Takeaways

  • -p host:container publishes ports.
  • -e KEY=VALUE sets env vars.
  • -v host:container mounts volumes.
  • -d detaches; --name names the container.
Previously: Module 2 covered images.
Today: You learned: All the essential docker run flags with examples.
Next: Lesson 17 covers detached vs foreground.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments