Guides/Docker using too much memory
Docker using too much memory on a Mac? How to find the container, and cap it
Quick answer
On a Mac, Docker runs every container inside one Linux virtual machine, so Activity Monitor shows a single large process, usually Virtual Machine Service for Docker, and not the containers. To see which container is using the memory, run `docker stats`. To cap the total, lower Memory limit in Docker Desktop’s Settings → Resources → Advanced; the default is half of your Mac’s memory. Resource Saver, in the same place, turns the virtual machine off when Docker Desktop is idle. Vitals, a system monitor for the Mac, shows every container’s memory, CPU, network and ports in its Containers tab, and stops a container from the menu bar.
How to find and cap Docker’s memory
- 01 Open Activity Monitor, click Memory, and type Docker in the search field. The largest row is the virtual machine that runs your containers; with Apple’s Virtualization framework it is named Virtual Machine Service for Docker. com.docker.backend is Docker Desktop itself.
- 02 In Terminal, run
docker stats --no-stream. Each row is a running container, and MEM USAGE / LIMIT shows what it uses and the most it may use. - 03 Stop what you are not using:
docker stopfollowed by the container’s name, ordocker compose downin a Compose project’s folder. - 04 Open Docker Desktop’s Settings → Resources → Advanced and lower Memory limit to a little above what
docker statsshows at your busiest. Apply the change; Docker Desktop restarts the virtual machine. - 05 Turn on Resource Saver in the same section, so the virtual machine shuts down while no containers are running.
OrbStack, Colima, Rancher Desktop and Podman also run containers in a virtual machine, each with its own memory setting. For Colima, colima start --memory 4 gives the virtual machine 4 GB.
Containers are a Linux feature, so on a Mac every engine runs them inside a small Linux virtual machine. macOS sees that machine as one process and has no idea which container inside it is using what. That is why Activity Monitor shows one process with several gigabytes and no containers at all, and why the answers are in Docker’s own tools. The table below matches what you see to what it is and what to do.
Where Docker’s memory goes
| What you see | What it is | What to do |
|---|---|---|
| Virtual Machine Service for Docker, several GB | The Linux virtual machine that runs every container | Lower Memory limit in Settings → Resources → Advanced |
| com.docker.backend | Docker Desktop’s own process | Usually small; restart Docker Desktop if it keeps growing |
| Memory stays high with no containers running | The virtual machine still holds memory it used | Turn on Resource Saver, or quit Docker Desktop |
| One container near its limit | It needs more, or it leaks | docker stats, and a per-container limit |
| Memory rises during image builds | Builds run in the same virtual machine | Normal; it falls when the build ends |
Why Activity Monitor shows one big Docker process
The virtual machine gets its memory from macOS like any app, up to the Memory limit you set. Inside it, Linux shares that memory among your containers and uses what is left to cache files, the way macOS does. From the outside all of it looks the same: one process holding a lot of memory.
Only the engine knows the split, which is what docker stats asks it for. The CPU % column there is a share of the virtual machine’s CPUs, and MEM % is a share of the container’s limit, or of the whole virtual machine when the container has none.
How much memory to give Docker
Docker Desktop takes half of your Mac’s memory by default: 8 GB on a 16 GB Mac. A typical development stack, an app server, a database and a cache, usually needs far less. Run your stack as you normally do, watch the total in docker stats at its busiest, and set Memory limit a little above it.
Set it too low and Linux inside the virtual machine stops containers that run out of memory. Run docker inspect --format '{{.State.OOMKilled}}' followed by a container’s name: it prints true when that happened. Raise the limit, or give that container a limit of its own so it cannot take the others down with it.
Set a memory limit per container
A limit on one container keeps a leaky service from filling the virtual machine. With docker run, add --memory 512m. In a Compose file, set mem_limit: 512m on the service. The container is stopped if it goes over, and docker stats shows the limit next to its usage.
Why Docker doesn’t give memory back
Stopping containers frees memory inside the virtual machine, but the machine does not always hand it back to macOS straight away, so its figure in Activity Monitor can stay high. Resource Saver returns all of it by turning the machine off when Docker Desktop is idle, and it starts again in a few seconds when a container needs it. Quitting Docker Desktop does the same.
Docker and disk space
Images, stopped containers, volumes and the build cache live in one disk image that grows as you work, and on a Mac it is counted in System Data. docker system df shows what each kind takes. docker system prune removes stopped containers, unused networks, dangling images and the build cache; add --volumes only if you are sure no volume holds data you need. Disk usage limit, next to Memory limit in Docker Desktop’s settings, caps it.
What Vitals adds
Vitals shows what the virtual machine will not tell macOS: the memory of every container.
- A Containers tab with memory, CPU, network, disk and published ports for every container, Compose projects grouped together
- Cards for the largest container and the one closest to its limit, and a chart of memory by container
- Docker Desktop is one row in the app list with its virtual machine counted in; click it to see the containers inside
- The containers in the menu bar dropdown too, where one click stops a container after asking. See how to stop Docker containers
- Docker Desktop, OrbStack, Colima, Rancher Desktop and Podman
Good to know
- Vitals reads container figures from the engine and never starts or removes containers. Stop is the only change it makes, and only when you ask.
- The tab appears while an engine is running.
Questions people ask
Why is Docker using so much memory on my Mac?
Docker runs containers in a Linux virtual machine that takes up to its Memory limit, half of your Mac’s memory by default. Lower Memory limit in Settings → Resources → Advanced, and run docker stats to see which container is using the most.
What is Virtual Machine Service for Docker?
The virtual machine Docker Desktop runs your containers in, when it uses Apple’s Virtualization framework. Its memory is everything the containers and Linux inside it use, up to Docker Desktop’s Memory limit.
How do I limit Docker’s memory on a Mac?
In Docker Desktop, open Settings → Resources → Advanced and lower Memory limit. For one container, use docker run --memory 512m, or mem_limit: 512m in a Compose file.
Why doesn’t Docker give memory back after I stop containers?
The virtual machine keeps some memory it has used even after containers stop. Turn on Resource Saver, which turns the machine off when Docker Desktop is idle, or quit Docker Desktop.
Why is Virtual Machine Service for Docker using so much CPU?
Usually a container is busy, and docker stats shows which one. If CPU stays high with no containers running, quit and reopen Docker Desktop and update it: high CPU with nothing running has been reported as a bug in some Docker Desktop versions.
How much memory should I give Docker on a Mac?
A little more than your containers use at their busiest, which docker stats shows. For a typical development stack that is often 2 to 4 GB, well below the default of half the Mac’s memory.
Is there an app that shows Docker container memory on a Mac?
Vitals has a Containers tab with each container’s memory, CPU, network, disk and ports, for Docker Desktop, OrbStack, Colima, Rancher Desktop and Podman. It also stops a container from the menu bar, after asking.
In the glossary
More guides
- Why is my Mac so slow
- What’s draining my Mac’s battery
- Which app is using my CPU or memory
- Why won’t my Mac sleep
- Chrome using too much memory
- Why are my Mac’s fans so loud
- How to control fan speed on a Mac
- How to free up RAM on a Mac
- How to stop Docker containers
- Volume mixer for Mac
- Activity Monitor alternatives
- iStat Menus alternatives
- Stats alternatives
- Task Manager for Mac
- Best system monitors for Mac
- Best menu bar monitors for Mac
- Best volume mixers for Mac