Create a disposable test service
A test service describes the dependencies and command needed to verify behavior. Here a web service serves a synthetic text response on an internal network; a test service requests it and compares its content. A health probe checks that the web endpoint responds before you run the test. The test service is placed in a tools profile so ordinary up starts only the web service. Explicitly targeting the test activates it. Use --no-deps after the web readiness check and --rm for a disposable test container. Success is exit status zero; the deliberately mismatched expectation should return nonzero. A health check is not a substitute for checking the actual response.
Read the development model
services: web: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sh - -c - mkdir -p /tmp/site && printf 'catalog-v14\n' > /tmp/site/index.html && exec httpd -f -p 8080 -h /tmp/site networks: - app healthcheck: test: - CMD - wget - -T - '2' - -q - -O - /dev/null - http://127.0.0.1:8080/ interval: 2s timeout: 3s retries: 5 test: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sh - -c - result=$$(wget -T 3 -qO- http://web:8080/) && [ "$$result" = catalog-v14 ] && printf "PASS\n" networks: - app profiles: - toolsnetworks: app: internal: trueManual lab
Manual lab only, not browser execution. Use a fresh approved disposable Linux VM with external egress blocked and a local Docker context. Check docker context show, docker version and docker compose version; verify the exact options and fields. Preload and verify a native-platform BusyBox 1.37 image digest, entrypoint and required applets; the tag is mutable. For builds verify a local Buildx docker driver using the reviewed base, with network blocked. Check all bm-v14 project and image names are unused and inherited Compose settings do not interfere. Use only a disposable copy of the supplied synthetic files; confirm UID 10001 can read source files. No public ports, external pulls/pushes, real secrets, broad host mounts or privileged containers. Run each line separately, stop on unexpected failures, clean only the lab and dispose of the VM. All results are predictions. Before Engine requests, verify the effective endpoint including DOCKER_HOST and DOCKER_CONTEXT; a project name does not select the daemon. Review inherited COMPOSE_ENV_FILES, COMPOSE_DISABLE_ENV_FILE, profile and project settings. Use a clean shell and the exact fixture directory. Inspect only synthetic config, logs and files. If a build is required, verify the effective builder can resolve the approved local base without egress; stop if build fails, never reuse a stale tag.
Open lab-fixtures/docker-compose-development/06-test-service/ in the extracted archive and run from a disposable copy of that folder.
docker compose -f compose.yaml -p bm-v14-test-service --profile tools config --quietdocker compose -f compose.yaml -p bm-v14-test-service up --wait --wait-timeout 25 --no-build --pull never webdocker compose -f compose.yaml -p bm-v14-test-service run --rm --no-deps -T --pull never test# Expected nonzero exit: wrong expected textdocker compose -f compose.yaml -p bm-v14-test-service run --rm --no-deps -T --pull never test sh -c 'result=$(wget -T 3 -qO- http://web:8080/) && [ "$result" = wrong-v14 ]'docker compose -f compose.yaml -p bm-v14-test-service run --rm --no-deps -T --pull never testThe positive test should exit zero and print PASS. The negative test should exit nonzero. No published ports are required. The test checks one response, not full application security or reliability. A nonzero code may also indicate a failed request or container startup. Diagnose the mismatch by checking web remains healthy and repeating the original positive test. Require PASS and zero exit for the positive control.
Clean only the named lab projects; no global prune or force removal. Retain the reviewed base image. A failed cleanup requires VM disposal and review.
docker compose -f compose.yaml -p bm-v14-test-service --profile tools downdocker compose -f compose.yaml -p bm-v14-test-service --profile tools ps -aCommon mistake
An HTTP response alone is not proof of correct content. A script must propagate a failed request or comparison rather than always printing PASS.
Manual practice
Predict the exit status for a wrong expected value and for a stopped web service. Explain why both cases matter.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Create a disposable test service — Knowledge check
Reason about development workflows and their effects.
What makes the content test useful?
Why put test in a profile?
What exit status should the test process return after a failed comparison?