Bird
0
0

You run this command:

medium📝 Troubleshoot Q14 of 15
Docker - Security
You run this command:
docker run --read-only alpine sh -c "touch /tmp/testfile"
But it fails with a permission error. What is the best fix?
ARemove the <code>--read-only</code> flag
BAdd a writable tmpfs mount for /tmp using <code>--tmpfs /tmp</code>
CRun the container as root user
DUse <code>-v /tmp:/tmp</code> to mount host /tmp
Step-by-Step Solution
Solution:
  1. Step 1: Identify cause of permission error

    The container filesystem is read-only, so creating files in /tmp fails.
  2. Step 2: Provide writable space with tmpfs

    Using --tmpfs /tmp mounts a writable temporary filesystem at /tmp, allowing file creation despite read-only root.
  3. Final Answer:

    Add a writable tmpfs mount for /tmp using --tmpfs /tmp -> Option B
  4. Quick Check:

    Writable tmpfs fixes write errors in read-only containers [OK]
Quick Trick: Use --tmpfs to add writable temp folders in read-only containers [OK]
Common Mistakes:
  • Removing --read-only loses security benefits
  • Mounting host /tmp may cause permission issues
  • Assuming root user can write despite read-only filesystem

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes