nerdexam
Cisco

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.

Containerization

Question

Which Docker command is used to start an interactive Bash shell in a running container named 'test'?

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)
  • A
    4% (1)
  • C
    93% (25)
  • D
    4% (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.

Adocker attach -it test /bin/bash

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.

Bdocker run -it test /bin/bash

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.

Cdocker exec -it test /bin/bashCorrect

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.

Ddocker run test /bin/bash

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

#Docker commands#Container management#Docker exec#Interactive shell

Community Discussion

No community discussion yet for this question.

Full 300-910 Practice