Docker Community Forums

Share and learn in the Docker community.

Docker Abusing Swap on macOS

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:


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.

EDIT

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.

1 Like

Disabling Use the new Virtualization framework in Experimental Features seems to have solved the issue. I will submit a bug report to Docker.

Clearly the beta still has some bugs! Had I remembered I was using the beta, this might have been easier to solve.