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...
debugging Docker Docker & Containers: From Zero to Production Docker Containers Module 3 — Working with Containers

Executing Commands Inside Running Containers with docker exec

Reviewed & accurate
AI Summary

What You'll Learn

Beginner

  • How to run commands inside a running container
  • How to open an interactive shell
  • When to use exec vs run
Terminalbash
# Open an interactive shell
docker exec -it web bash

# Run a single command
docker exec web ls /etc

# Run as root
docker exec -u root web whoami
docker rundocker exec
Creates a new containerRuns command in existing container
Container must not existContainer must be running

Practical Exercise

Run docker exec -it <name> bash
Run a one-off command with docker exec
Compare with docker run

Key Takeaways

  • docker exec <name> <command> runs a command in a running container.
  • docker exec -it <name> bash opens an interactive shell.
  • Use exec for debugging — not for permanent changes.
Previously: Lesson 18 covered logging.
Today: You learned: Run commands inside running containers without stopping them.
Next: Lesson 20 covers copying files.
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