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 run | docker exec |
|---|---|
| Creates a new container | Runs command in existing container |
| Container must not exist | Container must be running |
Practical Exercise
Run
docker exec -it <name> bashRun a one-off command with
docker execCompare with
docker runKey Takeaways
docker exec <name> <command>runs a command in a running container.docker exec -it <name> bashopens an interactive shell.- Use exec for debugging — not for permanent changes.
Comments
Comments
Post a Comment