Docker Community Forums

Share and learn in the Docker community.

How to see container swap memory

docker stats

This command can’t display swap memory info, and how to show the container swap memory?

I’m running on Ubuntu 19.10 (unsupported) - that being said this seems to work for me for viewing consumed swap of a specific container - assuming I’m interpreting this output correctly (easily tested):

foo@lab01:~$ docker ps -a  #find the CONTAINER ID
foo@lab01:~$ docker inspect 3a0a1wzf819 | grep -P '((Memory)|(PID))'  #Example using a CONTAINER ID
        "Memory": 0,
        "KernelMemory": 0,
        "KernelMemoryTCP": 0,
        "MemoryReservation": 0,
        "MemorySwap": 0,
        "MemorySwappiness": null,

Is that what you’re looking for?

I want to monitor real-time swap memory information, not the limit information in the configuration file.

I didnt set a limit of “0” on most of these - so outside unless they are defaults - hmph. That being said, you can use top for most things.

foo@lab-01:~$ docker inspect -f '{{.State.Pid}}' <CONTAINER ID>  #use this to find the PID of the container on the host

foo@lab-01:~$ top -p <Returned PID above>

An example would look like this:

foo@lab-01:~$ docker ps -a
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                                    NAMES
3a0a47a3e812        ubuntu   "/bin/bash:…"   4 hours ago         Up 4 hours  
foo@lab-01:~$ docker inspect -f '{{.State.Pid}}' 3a0a47a3e812
foo@lab-01:~$ top -p 17697

top - 04:07:56 up 12:19,  1 user,  load average: 0.00, 0.00, 0.00
Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.2 us,  0.0 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   3907.9 total,   2019.1 free,    437.8 used,   1451.1 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.   3229.3 avail Mem

17697 root      20   0  127176  26928  17592 S   0.0   0.7   0:02.88 ubuntu
1 Like

Thank you for providing me so much, this gave me some useful references

Very interesting, Good job and thanks for sharing such a good blog.