Run /bin/sh inside the running container web with standard input and a pseudo-terminal.
Which command is appropriate?
docker exec -it starts an additional interactive process in a running container; -i keeps input open and -t allocates a terminal.
Detailed explanation
docker exec -it web /bin/shCorrect. docker exec -it web /bin/sh opens the requested interactive shell.
Correct. docker exec -it web /bin/sh opens the requested interactive shell.
docker start -it /bin/sh webIncorrect. docker start starts a container, not a command with this argument order.
Incorrect. docker start starts a container, not a command with this argument order.
docker ps -it web /bin/shIncorrect. docker ps lists containers and does not execute a shell.
Incorrect. docker ps lists containers and does not execute a shell.
docker stop -it web /bin/shIncorrect. docker stop terminates a container.
Incorrect. docker stop terminates a container.
Try it yourself
An example you can run in a temporary verification environment.
docker exec --help 2>/dev/null | head -n 8 || trueExpected result
Dockerがある場合はexecのhelp。containerへ接続しないKey points
- docker exec
- -i
- -t
Notes
- Environment: Docker CLI helpのみ
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.