0
0
Dockerdevops~10 mins

Running containers as non-root in Docker - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the Dockerfile line to switch to a non-root user named 'appuser'.

Docker
USER [1]
Drag options to blanks, or click blank then click option'
Aroot
Bguest
Cadmin
Dappuser
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'root' runs the container as root, which is not secure.
2fill in blank
medium

Complete the Dockerfile command to create a non-root user named 'appuser' with home directory.

Docker
RUN adduser --disabled-password --gecos '' [1]
Drag options to blanks, or click blank then click option'
Aappuser
Broot
Cadmin
Dguest
Attempts:
3 left
💡 Hint
Common Mistakes
Creating 'root' or 'admin' users defeats the purpose of non-root containers.
3fill in blank
hard

Fix the error in the Dockerfile line to set ownership of /app directory to the non-root user 'appuser'.

Docker
RUN chown -R [1] /app
Drag options to blanks, or click blank then click option'
Aappuser:appuser
Bguest:guest
Croot:root
Dadmin:admin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'root:root' keeps root ownership, causing permission issues for non-root user.
4fill in blank
hard

Fill both blanks to run the container with user ID 1001 and group ID 1001.

Docker
docker run -u [1]:[2] myapp
Drag options to blanks, or click blank then click option'
A1001
Broot
C1000
Dappuser
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'root' or usernames instead of numeric IDs causes errors.
5fill in blank
hard

Fill all three blanks to create a Dockerfile snippet that creates a non-root user 'appuser', sets ownership of /app, and switches to that user.

Docker
RUN adduser --disabled-password --gecos '' [1] && \
    chown -R [2] /app
USER [3]
Drag options to blanks, or click blank then click option'
Aappuser
Broot
Cappuser:appuser
Dadmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'root' or 'admin' instead of 'appuser' defeats non-root purpose.