If your Docker Desktop Docker.raw file is exploding in size (10GB+), and you run frequent unit tests in a Lumen/Laravel environment, the culprit is likely orphaned files in /tmp.
This guide shows how to identify the bloat and move temporary test data to RAM for a faster, self-cleaning setup.
When Docker Desktop shows high disk usage, first check where the data is sitting:
# Check high-level breakdown
docker system df -v
# Check specific container internal usage
docker exec -it <container_name> du -sh /* | sort -hCommonly, /tmp or /var/log are the main offenders in PHP environments.
To instantly recover space without restarting everything, wipe the internal temporary files and build cache:
# Wipe container's temp folder
docker exec -it <container_name> sh -c "rm -rf /tmp/*"
# Reclaim space from old builds
docker builder prune -fInstead of writing temporary test data to your MacBook's SSD, mount /tmp as a tmpfs (RAM-based filesystem). This makes tests faster and auto-cleans everything on restart.
Pro
- Tests run significantly faster.
- Data is wiped instantly when the container stops.
- Saves your SSD from unnecessary wear.
Update your docker-compose.yml:
services:
your-api-service:
# ...
tmpfs:
# Mounts /tmp in RAM.
# 'exec' allows PHP script execution; 'mode=777' ensures write access.
- /tmp:exec,mode=777Ensure your testing environment doesn't force persistent file writes by updating phpunit.xml:
- Change
CACHE_DRIVERtoarray. - Change
SESSION_DRIVERtoarray.
Restart your containers to activate the RAM disk:
docker-compose down && docker-compose up -dVerify the mount is working:
docker exec -it <container_name> df -h /tmp
# Should show "Mounted on: /tmp" with type "tmpfs"Tip: If you still see high host-disk usage on your Mac, go to Docker Settings > Resources and click Apply & Restart to trigger the virtual disk's internal trimming process.
If you still have several GBs of "Reclaimable" space in docker system df, clear your old build layers:
docker builder prune -fNote: If your tests start failing with "Out of Memory," simply increase the Memory slider in Docker Desktop > Settings > Resources.