# How-to: Testare l'Enforcement dei Limiti Come verificare che i limiti delle risorse siano effettivamente applicati. ## Test 1: Verificare Configurazione ### Controllare nel compose file ```bash grep -A 10 "deploy:" docker-compose.yml | grep -E "cpus:|memory:" ``` ### Controllare nel container ```bash docker inspect lab03-web --format '{{.HostConfig.NanoCpus}}' # CPU (1e9 = 1 CPU) docker inspect lab03-web --format '{{.HostConfig.Memory}}' # Memory in bytes ``` ## Test 2: Stress Test CPU ### Avviare container con stress ```bash docker run -d --name stress-test \ --cpus='0.5' \ polinux/stress \ --cpu 1 \ --timeout 30s ``` ### Monitorare enforcement ```bash docker stats stress-test --no-stream ``` **Risultato atteso:** CPU non supera il 50% (0.5 CPU) ### Cleanup ```bash docker rm -f stress-test ``` ## Test 3: Stress Test Memory ### Avviare test OOM ```bash docker run -d --name mem-test \ --memory='512m' \ polinux/stress \ --vm 1 \ --vm-bytes 600M \ --timeout 60s ``` ### Verificare OOM kill ```bash docker ps -a --filter 'name=mem-test' ``` **Risultato atteso:** Container exited (code 137 = OOM killed) ### Cleanup ```bash docker rm -f mem-test ``` ## Test 4: Verifica con Script ```bash #!/bin/bash # verify-limits.sh for container in lab03-web lab03-app lab03-db; do echo "Container: $container" docker inspect "$container" --format ' CPUs: {{.HostConfig.NanoCpus}}' docker inspect "$container" --format ' Memory: {{.HostConfig.Memory}}' done ``` ## Vedi Anche - How-to: Check Resource Usage - Reference: EC2 Instance Mapping