Bird
Raised Fist0
Dockerdevops~20 mins

Capabilities and privilege control in Docker - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Capabilities Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Effect of Dropping a Capability in Docker
You run a Docker container with the command:
docker run --rm --cap-drop=NET_RAW alpine ping -c 1 8.8.8.8

What will be the output or result of this command?
Docker
docker run --rm --cap-drop=NET_RAW alpine ping -c 1 8.8.8.8
AThe ping command fails with 'ping: socket: Operation not permitted' error.
BThe ping command succeeds and shows the ping statistics.
CDocker throws an error: 'unknown capability: NET_RAW'.
DThe container starts but ping command is not found.
Attempts:
2 left
💡 Hint
Dropping NET_RAW capability disables raw socket creation needed by ping.
🧠 Conceptual
intermediate
1:00remaining
Understanding Privileged Mode in Docker
What is the main effect of running a Docker container with the --privileged flag?
AIt limits the container to only the default capabilities for security.
BIt grants the container all Linux capabilities and lifts most security restrictions.
CIt disables networking inside the container.
DIt runs the container with read-only filesystem.
Attempts:
2 left
💡 Hint
Think about what 'privileged' means in terms of access rights.
❓ Configuration
advanced
1:30remaining
Configuring a Docker Container to Add a Capability
You want to run a container that needs the ability to change system time. Which Docker run option correctly adds the required capability?
Adocker run --privileged=false alpine date
Bdocker run --cap-drop=SYS_TIME alpine date
Cdocker run --cap-add=SYS_TIME alpine date
Ddocker run --cap-add=NET_ADMIN alpine date
Attempts:
2 left
💡 Hint
Changing system time requires SYS_TIME capability.
❓ Troubleshoot
advanced
2:00remaining
Diagnosing Permission Issues with Docker Capabilities
A containerized application fails with 'Operation not permitted' when trying to modify network interfaces. The container was started with:
docker run --rm --cap-drop=NET_ADMIN myapp

What is the cause of the failure?
AThe image 'myapp' does not have ping installed.
BThe container lacks SYS_ADMIN capability needed for network changes.
CThe container must be run with --privileged to modify network.
DDropping NET_ADMIN capability prevents network interface modifications.
Attempts:
2 left
💡 Hint
NET_ADMIN controls network administration tasks.
✅ Best Practice
expert
2:30remaining
Security Best Practice for Running Containers with Capabilities
Which practice best improves container security regarding Linux capabilities?
AStart containers with no capabilities and add only those strictly required.
BUse default capabilities and never modify them.
CAlways run containers with --privileged for full functionality.
DStart containers with all capabilities and drop them as needed.
Attempts:
2 left
💡 Hint
Think about the principle of least privilege.

Practice

(1/5)
1. What does the --cap-drop option do when running a Docker container?
easy
A. Removes specific Linux capabilities from the container
B. Adds new capabilities to the container
C. Runs the container with full root privileges
D. Limits the container's CPU usage

Solution

  1. Step 1: Understand Docker capabilities

    Capabilities are Linux kernel permissions that control what a container can do on the host.
  2. Step 2: Role of --cap-drop

    This option removes specific capabilities from the container, reducing its privileges.
  3. Final Answer:

    Removes specific Linux capabilities from the container -> Option A
  4. Quick Check:

    --cap-drop means remove capabilities [OK]
Hint: Drop caps to reduce container privileges quickly [OK]
Common Mistakes:
  • Confusing --cap-drop with --cap-add
  • Thinking it controls CPU or memory
  • Assuming it grants root access
2. Which of the following is the correct syntax to add the NET_ADMIN capability to a Docker container?
easy
A. docker run --cap NET_ADMIN myimage
B. docker run --add-cap NET_ADMIN myimage
C. docker run --capability-add NET_ADMIN myimage
D. docker run --cap-add NET_ADMIN myimage

Solution

  1. Step 1: Recall Docker capability syntax

    The correct flag to add capabilities is --cap-add.
  2. Step 2: Match the correct command

    docker run --cap-add NET_ADMIN myimage uses --cap-add NET_ADMIN, which is the exact syntax Docker expects.
  3. Final Answer:

    docker run --cap-add NET_ADMIN myimage -> Option D
  4. Quick Check:

    Use --cap-add to add capabilities [OK]
Hint: Remember: add = --cap-add, drop = --cap-drop [OK]
Common Mistakes:
  • Using incorrect flags like --add-cap
  • Omitting the capability name
  • Using --cap or --capability-add which are invalid
3. What will be the effect of running this command?
docker run --cap-drop ALL --cap-add CHOWN alpine id
medium
A. The container has only the CHOWN capability enabled
B. The container has all capabilities except CHOWN
C. The container runs with full root privileges
D. The container will fail to start due to conflicting options

Solution

  1. Step 1: Analyze --cap-drop ALL

    This removes all Linux capabilities from the container, making it very restricted.
  2. Step 2: Analyze --cap-add CHOWN

    This adds back the CHOWN capability, allowing the container to change file ownership.
  3. Final Answer:

    The container has only the CHOWN capability enabled -> Option A
  4. Quick Check:

    Drop all then add one = only that one capability [OK]
Hint: Drop ALL then add one = only that one capability [OK]
Common Mistakes:
  • Thinking --cap-add adds on top without drop effect
  • Assuming container runs with full privileges
  • Believing conflicting options cause failure
4. You want to run a container with the SYS_TIME capability but accidentally use this command:
docker run --cap-drop SYS_TIME myimage

What is the problem and how to fix it?
medium
A. Problem: Syntax error in command. Fix: Remove --cap-drop
B. Problem: SYS_TIME is dropped, so container can't change time. Fix: Use --cap-add SYS_TIME
C. Problem: Container runs with full privileges. Fix: Add --cap-drop ALL
D. Problem: SYS_TIME is not a valid capability. Fix: Use a valid capability name

Solution

  1. Step 1: Understand the effect of --cap-drop SYS_TIME

    This removes the SYS_TIME capability, preventing the container from changing system time.
  2. Step 2: Correct the command to add the capability

    To allow changing time, use --cap-add SYS_TIME instead of dropping it.
  3. Final Answer:

    Problem: SYS_TIME is dropped, so container can't change time. Fix: Use --cap-add SYS_TIME -> Option B
  4. Quick Check:

    Drop removes, add grants capabilities [OK]
Hint: Add needed caps, don't drop them by mistake [OK]
Common Mistakes:
  • Confusing --cap-drop with --cap-add
  • Assuming dropping caps grants them
  • Thinking SYS_TIME is invalid capability
5. You want to run a container that can modify network settings but nothing else. Which command best limits privileges to only what is needed?
hard
A. docker run --cap-drop NET_ADMIN myimage
B. docker run --privileged myimage
C. docker run --cap-drop ALL --cap-add NET_ADMIN myimage
D. docker run --cap-add ALL myimage

Solution

  1. Step 1: Understand the goal

    The container should only have network admin rights, no other privileges.
  2. Step 2: Evaluate options

    docker run --cap-drop ALL --cap-add NET_ADMIN myimage drops all capabilities then adds only NET_ADMIN, perfectly limiting privileges.
  3. Step 3: Why others are wrong

    --privileged grants full privileges, --cap-add ALL adds all capabilities (too much), --cap-drop NET_ADMIN removes NET_ADMIN (opposite of goal).
  4. Final Answer:

    docker run --cap-drop ALL --cap-add NET_ADMIN myimage -> Option C
  5. Quick Check:

    Drop all then add needed cap = minimal privileges [OK]
Hint: Drop all caps, then add only needed ones [OK]
Common Mistakes:
  • Using --privileged which grants too many rights
  • Adding all capabilities instead of limiting
  • Dropping the needed capability by mistake
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard