How to check Docker CPU/RAM/Disk Usage on OSX
Published on Apr 3, 2020
Docker has become an indispensable tool in the contemporary development workflow. As trends in software development shift increasingly towards cloud infrastructure and microservices, Docker containers offer many advantages in terms of compatibility, rapid deployment, and productivity. When developing locally on OSX it can be challenging to get a clear picture of Docker’s resource consumption. In this article, you will learn how to get a clear picture of how to check Docker’s CPU, RAM, and Disk usage on your Mac and how to optimize performance for local development.
Docker, Mac, and Hyperkit
Docker on Mac has an unusual architecture which makes it difficult to get a clear picture of resource consumption. Docker relies on features unique to the Linux kernel like cgroups to implement containers and as a result, requires Linux to run. Because OSX is not Linux, Docker utilizes a large Linux VM, called hyperkit to run your containers.
As a result of this architecture, running
docker stats doesn’t tell you everything you need to know about resource consumption. You’ll get information about the footprint of your Docker containers, but not about hyperkit, the VM needed to run those containers. As we will see, hyperkit can be quite a resource hog, tending to eat more and more memory the longer it runs and the more containers you put on it.
On a Mac, to get a picture of Docker’s total resource consumption, including hyperkit, first launch the Activity Monitor application and search for Docker.
To check CPU, select the CPU tab.
Sorting by %CPU, here you can see com.docker.hyperkit is using 193.2%
To see RAM usage, simply select the Memory Tab within Activity Monitor.
Here you can see the memory footprint of Docker. Notice hyperkit is once again at the top of the list!
When it comes to disk space, Activity Monitor doesn’t give as much insight as Docker, itself. You can access information about Docker’s total disk usage on your machine by running
docker system df.
$ docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 29 7 4.722GB 4.195GB (88%) Containers 15 0 17MB 17MB (100%) Local Volumes 0 0 0B 0B Build Cache 0 0 0B 0B
How has Docker impacted your development experience?
We’re working on reducing Docker’s resource usage.
Fill out this 5-min survey to help us improve the Docker experience. No matter your background, we appreciate your help, and you might get a $150 Amazon gift card as thanks.
What to do if Docker is Running Slowly
Clear Unused Resources
There are some cleanup tasks you can run to optimize performance. Try running
docker system prune to clean quite a bit of the RAM, CPU, and disk consumed by Docker. Pruning can help quite a bit, but doesn’t release memory consumed by hyperkit and therefore isn’t enough in many cases.
Limit Docker Desktop
Docker desktop allows you to change the limits of hyperkit’s RAM/CPU/disk consumption. To access it find the docker preferences in the menu bar:
And navigate to the Resources tab:
Of course, you can also choose to close docker desktop when you’re not using it, freeing up resources.
Run Docker in the Cloud
Docker Machine lets you run Docker Engine on virtual hosts, either VMs on your local system or cloud providers. While Docker Machine can free up resources on your local machine, the configuration process isn’t exactly intuitive. Using Docker Machine also requires some changes to your workflow. However, you can learn to use it with some effort.
Kelda Blimp runs your existing local docker-compose.yml configuration in the Kelda Development Cloud without additional setup or changes to your workflow. Blimp is a drop-in SaaS replacement for Docker Compose that lets you continue to develop locally while outsourcing performance demands securely to remote hosts.
Kelda Blimp is a drop in replacement for Docker Compose that runs in the cloud. Run your existing docker-compose.yml and continue using key features like Volumes and Port Forwarding with no modifications.
Tutorial: How to Use Docker Volumes to Code Faster
Start running your Docker files in the cloud
Speed up your laptop by running your Dockerfiles on a SaaS replacement for Docker Compose.