117

I'm running docker desktop community 2.1.0.3 on MacOS Mojave. I've got 8GB of memory allocated to Docker, which already seems like a lot (that's half my RAM). Somehow even after exiting and then starting Docker for Mac again, which means no containers are running, docker is already exceeding the memory allocation by 1GB.

What is expected memory usage for docker with no containers running? Is there a memory leak in docker for mac or docker's hyperkit?

enter image description here

docker for mac memory leak

williamcodes
  • 6,317
  • 8
  • 32
  • 55
  • Do you have Kubernetes turned on? That costs some memory (though it shouldn’t fill an 8 GB VM). – David Maze Oct 09 '19 at 16:48
  • 2
    I see this on my local system FWIW, but I can right-click on the column header and also enable “Real Memory” and “Compressed Memory” columns. I suspect this column is over-counting virtual memory the process has made space for, but not actually requested real memory. – David Maze Oct 09 '19 at 16:53
  • I think it's related to this: https://github.com/docker/for-mac/issues/3232 – Stefano Oct 09 '19 at 19:40
  • 5
    In https://github.com/docker/for-mac/issues/3232 there is a link to [the following document: Understanding memory usage in Docker Desktop on Mac](https://docs.google.com/document/d/17ZiQC1Tp9iH320K-uqVLyiJmk4DHJ3c4zgQetJiKYQM/edit) which also mentions checking the "Real Memory". There are multiple experimentations with some nice details in there. – GabLeRoux Jan 24 '20 at 15:30
  • 1
    Docker also use %50 cpu on my macbook pro... – fuat Apr 11 '20 at 13:44
  • 2
    my cpu usage is 160% .My system mac os catalina 10.15.5, docker version 2.3.0.3 stable. my computer fan went crazy – melih sahin Jun 07 '20 at 11:37
  • 1
    my mac also does exactly what @melihsahin described. – Thayz Jul 09 '20 at 09:13

3 Answers3

96

As @GabLeRoux has shared in a comment, the "Real Memory" usage is much lower than what you see in the "Memory" column in Activity Monitor.

This document thoroughly explains memory usage on Mac OS with Docker Desktop and information is excerpted from there.

To see the "Real Memory" used by Docker, right-click the column names in Activity Monitor and Select "Real Memory". The value in this column is what's currently physically allocated to com.docker.hyperkit.

enter image description here

jbielick
  • 2,800
  • 17
  • 28
  • 21
    In my case hyperkit takes up 14.26GB of memory and 114MB of real memory. kernel_task takes up 11.44GB of real memory. When I stop hyperkit, kernel_task drops to 7.8GB – Anton Kuzmin Jul 13 '20 at 05:35
  • 4
    Ok. What's the solution to the issue ? If starting docker hangs system, apps freeze. Stopping docker works fine. Yes there are memory differences in the activity monitor interface. All I see is `com.docker.hyperkit` value is huge – devansvd Jan 09 '21 at 07:10
  • 13
    So the answer is "don't worry about it"? – MikeSchem May 04 '21 at 16:34
  • 26
    My fan is still spinning like crazy and my laptop is much slower even. – yudhiesh May 05 '21 at 14:39
  • 3
    If the real memory consumed by hyperkit is significantly lower than the allocated memory, you can configure Docker Desktop to use an amount much closer to the real memory used. – yair Jun 20 '21 at 12:51
  • @yudhiesh I've had that kernel_task issue more times than I care to remember. Turn off you machine for five minutes (letting it cool down) and then boot it up again. Wait five more minutes. If kernel_task is hogging resources still and yet you've been doing nothing, there's a real problem. The only solution I've ever found to that (despite 100s of other varying suggestions), is to format the machine and start from scratch. It's a real PITA. – freethebees Feb 07 '22 at 08:47
  • 2
    @yudhiesh ..yeah, Docker is bloatware. I have a newish Intel Macbook Pro and, if I have Docker Desktop and containers running, it will drain my battery in an hour or so, and it uses all my sys resources. I hope it works better on Apple Silicon. – Benji Mar 28 '22 at 12:28
  • 3
    Go to Docker Desktop > Preferences > Resources. In this page you can set "Memory" and "Swap" usage much lower than they are by default. – David Apr 07 '22 at 00:14
  • Setting my "CPUs" and "Memory" lower solved it for me (see below). No more fan. No more slow computer with maxed out memory usage. – Adam Apr 11 '22 at 18:51
  • 1
    My hyperkit shows memory 8.04GB, and real memory 8.22GB.. killing it on activity monitor restart it right away.. Worse: even after I stopped the containers, quit the agent and closed the app, it still lingers. But now the app doesn't open anymore and hyperkit just comes back as soon as I kill it.. – RaphaelDDL Jun 20 '22 at 13:38
  • 2
    Docker is not "bloatware" just because it is resource-intensive. Docker Desktop on macOS requires an extra layer of virtualisation as the underlying host OS is by definition not Linux. Anyone that's been using Docker on macOS for years can tell you that this has been getting better year over year. – Kye Oct 07 '22 at 01:45
36

Alternate answer: I reduced the number of CPUs and Memory Docker is allowed to use within the Docker Resources preferences. My computer is running faster and quieter now.

I just now put this in place, so time will tell if this solution works for me. Before it was making my computer max out on memory. Now it's significantly reduced.

Thank you for the note on real memory. I added that to my Activity Monitor.

UPDATE: It's been a few days now and my computer runs well below the max of memory and my fan runs at a minimum if at all.

Docker resources

Mac memory activity

Mac memory usage

Adam
  • 1,887
  • 1
  • 21
  • 21
  • 6
    This is what i was looking for really. My computer has now landed back on earth thank you! – Ransom Apr 15 '22 at 19:55
  • 3
    I don't know why people say Docker is better than VirtualBox when it comes to resources... these are the same kinds of settings in VirtualBox... limiting them has the same effect. – SteveExdia May 02 '22 at 00:56
  • 1
    This is a limit of Mac, having to spin up a virtual machine instead of running docker natively, with minimal memory usage. – Alex R Aug 17 '22 at 09:57
2

I think you shouldn't be using swap while ram is not full, for ssd health and speed

Adrian
  • 29
  • 1
  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 27 '22 at 01:02