Update check_docker.py #98
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The fix: Changed line 523-524 from:
pythonadjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache']
To:
pythoncache = inspection['memory_stats']['stats'].get('total_cache', 0) adjusted_usage = inspection['memory_stats']['usage'] - cach
Root Cause:
Some Docker versions don't include the total_cache field in memory_stats['stats']. The script attempts to access this field directly without checking if it exists first. Affected Docker/System:
AlmaLinux 9 / Python 3.12
Docker versions that don't provide total_cache in memory stats
Original Code (Lines 523-524):
python# Subtracting cache to match what
docker statsdoes. adjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache'] Fixed Code (Lines 523-525):python# Subtracting cache to match what
docker statsdoes. # Handle missing total_cache gracefully (some Docker versions don't provide it) cache = inspection['memory_stats']['stats'].get('total_cache', 0) adjusted_usage = inspection['memory_stats']['usage'] - cache Change Summary:Used .get('total_cache', 0) instead of direct dictionary access Returns 0 if total_cache doesn't exist (no cache to subtract) Maintains backward compatibility with Docker versions that do provide the field