0
0
Dockerdevops~20 mins

Running containers as non-root in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Non-root Container Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Dockerfile command?
Consider this Dockerfile snippet that sets a non-root user:

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
Aappuser
Broot
Cnobody
Ddocker
Attempts:
2 left
💡 Hint
The USER instruction changes the user for following commands.
Configuration
intermediate
2: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?
A
RUN adduser -u 1001 appuser
USER root
CMD ["./app"]
B
RUN useradd -m -u 1001 appuser
USER root
CMD ["./app"]
C
RUN adduser appuser
USER 1001
CMD ["./app"]
D
RUN adduser -u 1001 appuser
USER appuser
CMD ["./app"]
Attempts:
2 left
💡 Hint
The USER instruction sets the user for running commands and the app.
Troubleshoot
advanced
2:00remaining
Why does this container fail to start when running as non-root?
You have this Dockerfile snippet:

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?
AThe CMD syntax is invalid for non-root users.
BThe /app directory is owned by root and appuser has no permission to access it.
CThe USER instruction must be root to run node apps.
DThe useradd command did not create the user correctly.
Attempts:
2 left
💡 Hint
Check directory ownership and permissions for the app user.
🔀 Workflow
advanced
2: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':
A3,4,1,2
B4,3,1,2
C1,3,4,2
D3,1,4,2
Attempts:
2 left
💡 Hint
You must create the Dockerfile with user setup before building the image.
Best Practice
expert
2: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.
ARun containers as random users without setting file permissions.
BRun containers as root but restrict network access with firewall rules.
CCreate a dedicated user with a fixed UID and set proper file permissions in the image.
DUse the default root user but disable all container capabilities.
Attempts:
2 left
💡 Hint
Security best practices recommend fixed users and permissions.