Bird
0
0

Which Dockerfile snippet correctly creates a non-root user 'appuser' with UID and GID 1500 and sets it as the container user?

hard📝 Workflow Q8 of 15
Docker - Security
Which Dockerfile snippet correctly creates a non-root user 'appuser' with UID and GID 1500 and sets it as the container user?
ARUN useradd -r appuser USER 1500
BRUN addgroup -g 1500 appuser && adduser -u 1500 -G appuser -D appuser USER appuser
CUSER appuser RUN groupadd -g 1500 appuser
DRUN adduser appuser USER root
Step-by-Step Solution
Solution:
  1. Step 1: Create group and user with specific IDs

    Use addgroup and adduser with -g and -u flags to set GID and UID.
  2. Step 2: Set USER to 'appuser'

    USER instruction sets the container runtime user.
  3. Step 3: Verify other options

    RUN useradd -r appuser USER 1500 lacks group creation and uses USER with UID only; C sets USER before group; D sets USER to root.
  4. Final Answer:

    RUN addgroup -g 1500 appuser && adduser -u 1500 -G appuser -D appuser USER appuser -> Option B
  5. Quick Check:

    Create user/group with IDs, then set USER [OK]
Quick Trick: Create user/group with IDs, then USER [OK]
Common Mistakes:
  • Setting USER before creating user
  • Not specifying UID/GID explicitly
  • Running container as root unintentionally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes