nerdexam
Cisco

300-910 · Question #78

A developer is containerizing an application. The container "devnetprod" has been run in detached mode to output the container ID with the command: docker run -d devnetprod…

The correct answer is B. docker exec -it devnetprod /bin/bash. To interact with a running Docker container, the docker exec command is used with the container's name or ID and the -it flags for an interactive TTY session.

Containerization

Question

A developer is containerizing an application. The container "devnetprod" has been run in detached mode to output the container ID with the command: docker run -d devnetprod 1b487caec32a75ce2a74447060455ad838269e8747f4314769fa287 Which command must be used to start an interactive Bash shell running the container?

Exhibit

300-910 question #78 exhibit

Options

  • Adocker exec -it 1b487caec32a /bin/bash
  • Bdocker exec -it devnetprod /bin/bash
  • Cdocker run -it devnetprod /bin/bash
  • Ddocker run -it 1b48caec32a /bin/bash

How the community answered

(30 responses)
  • A
    7% (2)
  • B
    90% (27)
  • C
    3% (1)

Why each option

To interact with a running Docker container, the `docker exec` command is used with the container's name or ID and the `-it` flags for an interactive TTY session.

Adocker exec -it 1b487caec32a /bin/bash

Using the container ID `1b487caec32a` (truncated) with `docker exec` would technically work if the ID was complete and correct, but generally, referring to containers by name (`devnetprod`) is preferred for readability and consistency.

Bdocker exec -it devnetprod /bin/bashCorrect

The `docker exec -it devnetprod /bin/bash` command is correct because `docker exec` is used to run a command in a *running* container. The `-it` flags allocate a pseudo-TTY and keep STDIN open for an interactive session, and `devnetprod` is the container's name. This allows an interactive Bash shell to be started inside the already running detached container.

Cdocker run -it devnetprod /bin/bash

`docker run` is used to *start a new* container from an image, not to execute a command within an *already running* container. This would attempt to create a new container named `devnetprod` (if it was an image name) and run bash in it, not interact with the existing one.

Ddocker run -it 1b48caec32a /bin/bash

`docker run` is incorrect for executing a command in a running container, and using a truncated container ID with `docker run` is also incorrect syntax for starting a container by ID.

Concept tested: Docker container interaction (exec)

Source: https://docs.docker.com/engine/reference/commandline/exec/

Topics

#Docker#Container management#docker exec command#Interactive shell

Community Discussion

No community discussion yet for this question.

Full 300-910 Practice