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.
docker start -it /bin/sh webIncorrect. 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.
docker stop -it web /bin/shIncorrect. 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のみ
- Use a disposable VM or container when validating lifecycle commands.
- Exact command output can vary slightly by distribution and runtime version.
Foundation review
Identify the layer
The process started by exec is separate from the container's main process and does not create a new container.
Check the side effect
Verify that the target is running and that the requested shell exists in its user space before attaching.