Hint: Exec runs commands inside container, not on host [OK]
Common Mistakes:
Thinking exec runs commands on host
Assuming exec starts new containers
Believing ls is invalid inside containers
4. You run docker exec webapp bash but get the error: the input device is not a TTY. What is the likely fix?
medium
A. Stop the container and restart it
B. Add the -it flags to enable interactive terminal
C. Use docker run instead of docker exec
D. Remove the bash command from the exec
Solution
Step 1: Understand the error about TTY
The error means the command expects an interactive terminal but none was allocated.
Step 2: Fix by adding -it flags
Adding -it allocates a pseudo-TTY and keeps stdin open, enabling interactive shells inside containers.
Final Answer:
Add the -it flags to enable interactive terminal -> Option B
Quick Check:
Interactive shells need -it flags [OK]
Hint: Use -it for interactive commands to avoid TTY errors [OK]
Common Mistakes:
Ignoring the need for -it flags
Restarting container unnecessarily
Confusing exec with run command
5. You want to check the environment variables inside a running container named api. Which command correctly does this and shows output interactively?
hard
A. docker exec -it api env
B. docker exec env api
C. docker exec -it env api
D. docker exec api -it env
Solution
Step 1: Identify the need for interactive output
To see environment variables interactively, you need to allocate a TTY and keep stdin open using -it.
Step 2: Check command syntax
docker exec -it api env correctly places -it after docker exec, then container name api, then command env. Other options have wrong order or missing flags.
Final Answer:
docker exec -it api env -> Option A
Quick Check:
Use -it before container name for interactive commands [OK]
Hint: Place -it right after exec for interactive commands [OK]
Common Mistakes:
Placing -it after container or command
Omitting -it for interactive output
Swapping command and container name
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.