0
0
Dockerdevops~20 mins

Opening a shell in container in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shell Mastery in Containers
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Opening an interactive shell inside a running container
You have a running Docker container named webapp. Which command opens an interactive bash shell inside it?
Adocker exec -it webapp bash
Bdocker run -it webapp bash
Cdocker start -it webapp bash
Ddocker attach webapp bash
Attempts:
2 left
💡 Hint
Use docker exec to run commands inside a running container.
💻 Command Output
intermediate
2:00remaining
Opening a shell in a container without bash
You want to open a shell inside a running container named db, but it does not have bash installed. Which command will open a shell using sh instead?
Adocker exec -it db bash
Bdocker exec -it db sh
Cdocker run -it db sh
Ddocker attach db sh
Attempts:
2 left
💡 Hint
Try using a simpler shell like sh if bash is missing.
Troubleshoot
advanced
2:00remaining
Why does 'docker exec -it container_name bash' fail with 'exec: "bash": executable file not found'?
You run docker exec -it mycontainer bash but get the error exec: "bash": executable file not found in $PATH. What is the most likely cause?
AThe container image does not have bash installed.
BThe container is not running.
CYou forgot to use sudo before the command.
DThe Docker daemon is not running.
Attempts:
2 left
💡 Hint
Check what shells are available inside the container.
🔀 Workflow
advanced
2:30remaining
Steps to open a shell in a stopped container
You have a stopped container named app. Which sequence of commands correctly opens an interactive shell inside it?
A2,1
B3,4
C1,2
D4,1
Attempts:
2 left
💡 Hint
You must start the container before executing commands inside it.
Best Practice
expert
3:00remaining
Best practice for opening a shell in a container for debugging
Which practice is best when you want to debug a running container without affecting its main process?
AUse <code>docker attach container_name</code> to connect to the main process.
BStop the container and run <code>docker run -it container_name bash</code>.
CRestart the container with <code>docker restart container_name</code> and then open a shell.
DUse <code>docker exec -it container_name sh</code> to open a new shell session.
Attempts:
2 left
💡 Hint
Opening a separate shell session avoids interfering with the main process.