Compose networks and service isolation
Use explicit networks to express which services should communicate. The sample has web and client on an internal application network and auditor on a separate internal network. The top-level network definitions create the project resources; each service networks list grants membership. A client uses the web service name and its container port 8080, not a host-published port. Services attached to different networks do not normally resolve or directly reach one another by service name. Internal networks limit external connectivity, but do not replace authorization, host isolation or application authentication.
Read the configuration
services: web: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sh - -c - mkdir -p /tmp/site && printf 'catalog-v13\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 client: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sh - -c - exec sleep 300 networks: - app auditor: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sh - -c - exec sleep 300 networks: - auditnetworks: app: internal: true audit: 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 support for each flag and field. Preload and verify the native-platform BusyBox 1.37 digest, entrypoint and required applets; the tag is mutable. Ensure bm-v13 project/image/volume names are unused and no inherited COMPOSE_PROFILES or BM13 variables interfere. Use only the synthetic files here, on a disposable copy. File-backed config/secret mounts are limited to these exact files; verify UID 10001 can read them. No public ports, external pulls/pushes, real secrets or host directory mounts. Run each command individually; stop on unexpected failures, perform scoped cleanup and dispose of the VM. Explicit negative probes are expected to fail. All results below 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-configuration/03-networks/ in the extracted archive and run from a disposable copy of that folder.
docker compose -f compose.yaml -p bm-v13-networks config --quietdocker compose -f compose.yaml -p bm-v13-networks up --wait --wait-timeout 25 --no-build --pull neverdocker compose -f compose.yaml -p bm-v13-networks exec -T client wget -T 3 -qO- http://web:8080/# Expected failure: auditor is not a member of appdocker compose -f compose.yaml -p bm-v13-networks exec -T auditor wget -T 3 -qO- http://web:8080/docker compose -f compose.yaml -p bm-v13-networks exec -T client wget -T 3 -qO- http://web:8080/Once web is ready, client should receive catalog-v13. The same request from auditor is expected to fail; this is one negative probe, not proof of complete isolation. No host ports are published. Require exact positive body and verify auditor remains running. Inspect the effective network memberships and diagnose the negative request (for example, name resolution failure); repeat the positive request afterward. A CLI failure alone is not network evidence.
Clean only this disposable project. No global prune or force removal. Verify the project is empty. Retain the base image.
docker compose -f compose.yaml -p bm-v13-networks downdocker compose -f compose.yaml -p bm-v13-networks ps -aCommon mistake
Declaring a network does not attach every service to it. Check memberships and actual permitted paths rather than relying on the name of a network.
Manual practice
Draw the two networks and predict the reachability matrix. Explain why moving auditor onto app would change the result and why that would require review.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Compose networks and service isolation — Knowledge check
Reason about the Compose configuration and its consequences.
What allows client to use web by name?
Which port is used inside app?
Does internal guarantee all security?