0
0
Dockerdevops~20 mins

Executing commands with docker exec - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Exec Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Output of docker exec with environment variable
What is the output of this command if the container named webapp has an environment variable APP_MODE=production set?

docker exec webapp printenv APP_MODE
Docker
docker exec webapp printenv APP_MODE
AAPP_MODE
BError: No such container: webapp
Cprintenv APP_MODE
Dproduction
Attempts:
2 left
💡 Hint
The command prints the value of the environment variable inside the container.
💻 Command Output
intermediate
1:30remaining
Effect of docker exec with interactive shell
What happens when you run this command?

docker exec -it mycontainer /bin/bash
Docker
docker exec -it mycontainer /bin/bash
AStarts an interactive bash shell inside the running container named mycontainer
BStops the container named mycontainer
CShows the logs of the container named mycontainer
DCreates a new container named mycontainer
Attempts:
2 left
💡 Hint
The flags -i and -t are used for interactive terminal sessions.
Troubleshoot
advanced
2:00remaining
Troubleshooting docker exec permission error
You run docker exec mycontainer ls /root and get a permission denied error. What is the most likely cause?
AThe /root directory does not exist inside the container
BThe container is not running
CThe user inside the container does not have permission to access /root directory
DThe docker daemon is not started
Attempts:
2 left
💡 Hint
Consider user permissions inside the container.
🔀 Workflow
advanced
2:30remaining
Correct sequence to update a file inside a running container
You want to update a configuration file inside a running container named app. Which sequence of commands is correct?
A2,1,3,4
B1,2,3,4
C1,3,2,4
D4,1,2,3
Attempts:
2 left
💡 Hint
Copy the file first, then move it, verify, and restart the service.
Best Practice
expert
2:00remaining
Best practice for running a command as root inside a container
Which docker exec command correctly runs apt-get update as root inside a container named db?
Adocker exec -u root db apt-get update
Bdocker exec db -u root apt-get update
Cdocker exec db apt-get update -u root
Ddocker exec --user db root apt-get update
Attempts:
2 left
💡 Hint
The -u or --user flag must come before the container name.