Challenge - 5 Problems
Docker Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
Output of a Docker test run command
What is the output of running this Docker command to execute tests inside a container?
Docker
docker run --rm -v $(pwd):/app -w /app python:3.12 python -m unittest discover tests
Attempts:
2 left
💡 Hint
The command mounts the current directory and runs Python tests inside the container.
✗ Incorrect
The command mounts the current directory into /app in the container, sets the working directory to /app, and runs Python unittest discovery on the 'tests' folder. If tests exist and run successfully, it outputs the number of tests run and 'OK'.
🧠 Conceptual
intermediate1:00remaining
Understanding Docker test container isolation
Why is it beneficial to run tests inside Docker containers instead of directly on the host machine?
Attempts:
2 left
💡 Hint
Think about environment differences between machines.
✗ Incorrect
Running tests in containers isolates them from the host environment, ensuring consistent dependencies and configurations. This avoids issues caused by differences in host setups.
❓ Configuration
advanced2:00remaining
Dockerfile for running tests with environment variables
Which Dockerfile snippet correctly sets an environment variable and runs tests using pytest inside the container?
Attempts:
2 left
💡 Hint
Environment variables should be set before the command runs.
✗ Incorrect
Option A correctly sets the environment variable TEST_ENV before running the tests. ENV must come before CMD to be effective. CMD uses exec form to run pytest.
❓ Troubleshoot
advanced1:30remaining
Diagnosing test failures in Docker container
You run tests inside a Docker container but get this error: "ModuleNotFoundError: No module named 'requests'". What is the most likely cause?
Attempts:
2 left
💡 Hint
Think about Python dependencies inside containers.
✗ Incorrect
The error means the Python package 'requests' is missing inside the container environment. It must be installed via pip in the Dockerfile or before running tests.
🔀 Workflow
expert2:30remaining
Best workflow to run tests in CI with Docker
Which sequence of steps is the best workflow to run automated tests in a CI pipeline using Docker containers?
Attempts:
2 left
💡 Hint
Consider the logical order of preparing images, running tests, and pushing images.
✗ Incorrect
First pull the latest base image (4) to get updates, then build the image (1), run tests inside the container (2), and if tests pass, push the image to the registry (3).