Challenge - 5 Problems
Non-root Container Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Dockerfile command?
Consider this Dockerfile snippet that sets a non-root user:
What will be the output of the
FROM alpine:latest RUN adduser -D appuser USER appuser RUN whoami
What will be the output of the
whoami command inside the container?Docker
FROM alpine:latest RUN adduser -D appuser USER appuser RUN whoami
Attempts:
2 left
💡 Hint
The USER instruction changes the user for following commands.
✗ Incorrect
The USER instruction switches the user to 'appuser'. So the 'whoami' command runs as 'appuser' and outputs 'appuser'.
❓ Configuration
intermediate2:00remaining
Which Dockerfile snippet correctly runs a process as non-root user?
You want to run your application inside a container as a user named 'appuser' with UID 1001. Which Dockerfile snippet correctly creates this user and runs the app as that user?
Attempts:
2 left
💡 Hint
The USER instruction sets the user for running commands and the app.
✗ Incorrect
Option D creates the user with UID 1001, switches to that user, and runs the app as that user. Other options either keep root or use wrong USER syntax.
❓ Troubleshoot
advanced2:00remaining
Why does this container fail to start when running as non-root?
You have this Dockerfile snippet:
The container fails with a permission error when trying to access /app directory. What is the most likely cause?
FROM node:18 RUN useradd -m appuser USER appuser CMD ["node", "app.js"]
The container fails with a permission error when trying to access /app directory. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check directory ownership and permissions for the app user.
✗ Incorrect
The appuser cannot access /app if it is owned by root without proper permissions. This causes permission errors when running as non-root.
🔀 Workflow
advanced2:00remaining
What is the correct order to run these Docker commands to build and run a container as non-root?
Arrange these commands in the correct order to build an image and run a container as a non-root user named 'appuser':
Attempts:
2 left
💡 Hint
You must create the Dockerfile with user setup before building the image.
✗ Incorrect
First create the Dockerfile with USER and user creation, then build the image, then run the container.
✅ Best Practice
expert2:00remaining
Which practice is best for running containers as non-root in production?
Select the best practice for running containers as non-root users in a secure production environment.
Attempts:
2 left
💡 Hint
Security best practices recommend fixed users and permissions.
✗ Incorrect
Creating a dedicated user with fixed UID and setting file permissions ensures predictable security and avoids permission issues.