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| Flag | Purpose |
|---|---|
-d | Detached (background) |
-it | Interactive terminal |
-p | Port mapping |
-e | Environment variable |
-v | Volume mount |
--name | Container name |
Practical Exercise
Run nginx with port mapping
Run with environment variables
Run with a volume mount
Key Takeaways
-p host:containerpublishes ports.-e KEY=VALUEsets env vars.-v host:containermounts volumes.-ddetaches;--namenames 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.
Today: You learned: All the essential docker run flags with examples.
Next: Lesson 17 covers detached vs foreground.
Comments
Comments
Post a Comment