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
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:
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.
When asking this same question on Stack Exchange, it was pointed out that I was using the beta Virtualization Framework. I’m now trying Docker without that option enabled. I’ll see what happens.