Bird
0
0

What will be the output of this command?

medium📝 Command Output Q4 of 15
Docker - Security
What will be the output of this command?
docker run --read-only alpine sh -c "touch /file && echo success || echo fail"
Afail
Bsuccess
Ctouch: cannot touch '/file': Read-only file system
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand the command behavior on read-only filesystem

    The touch /file command tries to create a file in the root filesystem, which is read-only, so it fails.
  2. Step 2: Analyze shell logic

    Because touch fails, the shell runs the command after ||, printing "fail".
  3. Final Answer:

    fail -> Option A
  4. Quick Check:

    Write fails on read-only FS, so shell prints fail [OK]
Quick Trick: Write fails on read-only FS, shell fallback triggers [OK]
Common Mistakes:
  • Expecting success despite read-only
  • Confusing shell logic with && and ||
  • Ignoring error messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes