Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Docker Tip #21: Measure Your Docker Containers' Resources

docker-tips-and-tricks.jpg

Docker has a built in command to let you see how much CPU, memory, network I/O and block I/O your containers are using.

Quick Jump:

It’s very beneficial to see how much resources your containers are using. Armed with that knowledge, you can then provision machines that match up with how much resources your containers use in total. You’ll save money in the long run by doing that.

All you have to do is run docker stats on a machine that’s running Docker.

Live stream of stats about your containers:
CONTAINER       CPU %      MEM USAGE / LIMIT      MEM %    NET I/O            BLOCK I/O
9c2f69f8631e    25.75%     5.188MiB / 5.877GiB    0.09%    6.32MB / 7.63MB    34.2MB / 37.5MB
c6d1f0738982    0.29%      44.31MiB / 5.877GiB    0.74%    24.5kB / 4.99kB    26.5MB / 0B
5a52bc636ec3    14.93%     948KiB / 5.877GiB      0.02%    4.79MB / 3.73MB    2.7MB / 0B
f9f8d3140cd3    0.75%      27.59MiB / 5.877GiB    0.46%    26.1kB / 0B        14.8MB / 0B
e60048f81636    137.01%    48.8MiB / 5.877GiB     0.81%    11.4MB / 11.1MB    41.3MB / 0B

Update: Over time Docker added the NAME and PID columns (not shown above) to the output.

If you’d like, you can narrow it down to a specific container by adding in 1 or more container names / IDs after the command. For example docker stats 9c2f c6d1.

You can even use the --format flag to limit what you see.

Limit the output to only show CPU and memory stats:
$ docker stats --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"

CONTAINER           CPU %               MEM USAGE / LIMIT
9c2f69f8631e        24.25%              5.203MiB / 5.877GiB
c6d1f0738982        0.09%               42.78MiB / 5.877GiB
5a52bc636ec3        14.66%              948KiB / 5.877GiB
f9f8d3140cd3        0.74%               27.55MiB / 5.877GiB
e60048f81636        134.69%             49.63MiB / 5.877GiB

Free Intro to Docker Email Course

Over 5 days you'll get 1 email per day that includes video and text from the premium Dive Into Docker course. By the end of the 5 days you'll have hands on experience using Docker to serve a website.



Comments