Bird
0
0

Which of the following docker run commands correctly runs tests inside a container and removes the container after completion?

easy📝 Syntax Q12 of 15
Docker - in CI/CD
Which of the following docker run commands correctly runs tests inside a container and removes the container after completion?
Adocker run -it myapp pytest
Bdocker run --name testcontainer myapp pytest
Cdocker run -d myapp pytest
Ddocker run --rm myapp pytest
Step-by-Step Solution
Solution:
  1. Step 1: Understand the --rm flag

    The --rm option tells Docker to remove the container after it finishes running.
  2. Step 2: Match command to requirement

    docker run --rm myapp pytest uses --rm and runs pytest inside the container, which fits the question.
  3. Final Answer:

    docker run --rm myapp pytest -> Option D
  4. Quick Check:

    --rm removes container after run [OK]
Quick Trick: Use --rm to auto-remove containers after tests [OK]
Common Mistakes:
  • Using -d runs container detached, not suitable for tests
  • Forgetting --rm leaves stopped containers
  • Using --name does not remove container automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes