Docker Abusing Swap on macOS Monterey
On macOS Monterey, the Docker process is using many GB of swap (virtual memory). So much swap, in fact, that my SSD filled up and caused file corruption. Here are some things I've done to try to limit the swap usage:
Running the container with --memory-swap
limited:
docker run -dp <port stuff> -v <bind volume stuff> --cpus="2" -m 2g --memory-swap 6g --name <name> <image>
Limiting swap usage in Docker Desktop:
Here's what continues to happen: After 24 hours (the swap usage increases throughout the day):
The Docker process is the one using tons of swap, while the container (com.apple.Virtualizations.VirtualMachine
) stays within its limits.
Restarting the container does not free up swap, while restarting the docker daemon does.
Is there anything I can do to prevent this abuse of swap? I don't want to disable swap entirely, but I'd like to keep Docker down to a few GB at most.
Disabling Use the new Virtualization framework in Experimental Features seems to have solved the issue. I will submit a bug report to Docker.