2. Which of the following is the correct syntax to open a shell inside a running Docker container named webapp?
easy
A. docker exec -it webapp /bin/sh
B. docker start -it webapp /bin/sh
C. docker run -it webapp /bin/sh
D. docker exec webapp -it /bin/sh
Solution
Step 1: Recall the correct order of docker exec flags
The -it flags must come immediately after docker exec and before the container name.
Step 2: Check the command structure
The correct syntax is docker exec -it <container> <shell>. docker exec -it webapp /bin/sh matches this exactly.
Final Answer:
docker exec -it webapp /bin/sh -> Option A
Quick Check:
Flags -it come before container name [OK]
Hint: Flags -it always come right after exec command [OK]
Common Mistakes:
Placing -it after container name
Using docker run instead of exec
Using docker start with shell command
3. Given a running container named db, what will be the output of the command docker exec -it db /bin/false?
medium
A. The command exits immediately with no shell opened
B. Error: container not found
C. An interactive shell opens inside the container
D. The container stops running
Solution
Step 1: Understand the command /bin/false
The command /bin/false is a program that immediately exits with a failure status and does not open a shell.
Step 2: Predict the command behavior inside the container
Running docker exec -it db /bin/false will run /bin/false inside the container, which exits immediately without opening a shell.
Final Answer:
The command exits immediately with no shell opened -> Option A
Quick Check:
/bin/false exits immediately, no shell [OK]
Hint: Commands like /bin/false exit immediately, no shell [OK]
Common Mistakes:
Expecting a shell to open
Confusing container not found error
Thinking container stops after exec
4. You try to open a shell inside a running container with docker exec -it mycontainer /bin/bash but get the error: OCI runtime exec failed: exec failed: container_linux.go:xxx: exec: "/bin/bash": stat /bin/bash: no such file or directory. What is the best way to fix this?
medium
A. Restart the Docker daemon
B. Use /bin/sh instead of /bin/bash
C. Rebuild the container image
D. Stop and remove the container
Solution
Step 1: Analyze the error message
The error says /bin/bash does not exist inside the container, so the shell is missing.
Step 2: Choose an alternative shell
Many containers have /bin/sh instead of /bin/bash. Using /bin/sh usually works.
Final Answer:
Use /bin/sh instead of /bin/bash -> Option B
Quick Check:
Use available shell like /bin/sh if /bin/bash missing [OK]
Hint: Try /bin/sh if /bin/bash not found inside container [OK]
Common Mistakes:
Restarting Docker daemon unnecessarily
Rebuilding image without checking shell availability
Removing container without trying alternative shells
5. You want to open a shell inside a running container named app but it does not have /bin/bash or /bin/sh. Which command can you try to open a shell if ash is installed inside the container?
hard
A. docker exec -it app /bin/zsh
B. docker exec -it app /bin/bash
C. docker exec -it app /bin/sh
D. docker exec -it app /bin/ash
Solution
Step 1: Identify available shells inside container
If /bin/bash and /bin/sh are missing, but ash is installed, you can use /bin/ash to open a shell.
Step 2: Use docker exec with the correct shell path
The command docker exec -it app /bin/ash opens an interactive shell using ash inside the container.
Final Answer:
docker exec -it app /bin/ash -> Option D
Quick Check:
Use shell installed inside container, e.g. /bin/ash [OK]
Hint: Try shells like /bin/ash if bash and sh missing [OK]
Common Mistakes:
Assuming bash or sh always exist
Using wrong shell path
Not checking installed shells inside container
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.