300-910 · Question #1
Which Docker command is used to start an interactive Bash shell in a running container named 'test'?
The correct answer is C. docker exec -it test /bin/bash. The docker exec command is used to run a new command in a running Docker container, making it suitable for starting an interactive Bash shell.
Question
Options
- Adocker attach -it test /bin/bash
- Bdocker run -it test /bin/bash
- Cdocker exec -it test /bin/bash
- Ddocker run test /bin/bash
How the community answered
(27 responses)- A4% (1)
- C93% (25)
- D4% (1)
Why each option
The `docker exec` command is used to run a new command in a running Docker container, making it suitable for starting an interactive Bash shell.
The `docker attach` command connects to the main process of a *running* container, not for executing a new, separate command like `/bin/bash` within it.
The `docker run` command is used to create and start a *new* container from an image, not to execute a command within an already running container.
The `docker exec` command is specifically designed to execute a new command inside a *running* container, making it the correct choice for starting an interactive Bash shell in an already existing 'test' container. The `-it` flags are crucial for allocating a pseudo-TTY and keeping standard input open, enabling interactive use of the shell.
The `docker run` command creates a new container, and without the `-it` flags, it would not provide an interactive terminal for the Bash shell.
Concept tested: Docker container execution and interaction
Source: https://docs.docker.com/engine/reference/commandline/exec/
Topics
Community Discussion
No community discussion yet for this question.