0
0
Dockerdevops~5 mins

Opening a shell in container in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What command lets you open an interactive shell inside a running Docker container?
Use docker exec -it <container_name_or_id> /bin/bash to open an interactive bash shell inside a running container.
Click to reveal answer
beginner
What does the -it option mean in docker exec -it?
-i means interactive mode to keep STDIN open, and -t allocates a pseudo-TTY so you get a terminal interface.
Click to reveal answer
beginner
How do you open a shell in a container that uses sh instead of bash?
Use docker exec -it <container> /bin/sh because some containers have only sh shell.
Click to reveal answer
intermediate
What is the difference between docker exec and docker attach?
docker exec runs a new command (like a shell) inside the container, while docker attach connects to the main process's input/output of the container.
Click to reveal answer
beginner
Why might you want to open a shell inside a running container?
To inspect the container's file system, debug running processes, or manually run commands inside the container environment.
Click to reveal answer
Which command opens an interactive bash shell inside a running Docker container named 'webapp'?
Adocker run -it webapp /bin/bash
Bdocker exec -it webapp /bin/bash
Cdocker start -it webapp /bin/bash
Ddocker attach webapp /bin/bash
What does the -t option do in the command docker exec -it?
ARuns the container in detached mode
BStops the container after command finishes
CSpecifies the target container
DAllocates a pseudo-TTY for terminal interface
If a container does not have bash installed, which shell is commonly available?
A/bin/sh
B/bin/zsh
C/bin/fish
D/bin/csh
Which command connects to the main process's input/output of a running container?
Adocker attach
Bdocker exec
Cdocker run
Ddocker shell
Why is opening a shell inside a container useful?
ATo permanently change container settings
BTo delete the container
CTo inspect and debug the container environment
DTo update Docker software
Explain how to open an interactive shell inside a running Docker container and why you might do this.
Think about the command and the purpose of opening a shell.
You got /3 concepts.
    Describe the difference between docker exec and docker attach commands.
    Consider how each command interacts with the container.
    You got /3 concepts.